DemoTiger Posted February 6, 2018 Share Posted February 6, 2018 Hello, I want to display Only selected custom-field, Currently 3 fields are available but I wish to display only any one field. For example: I use {foreach $customfields.NUMBERHERE as $customfield} but it does not work ;/ It does not display correctly. Here is my code. I only change {foreach $customfields line... } <div class="sub-heading"> <span>{$LANG.orderadditionalrequiredinfo}</span> </div> <div class="field-container"> <div class="row"> {foreach $customfields.2 as $customfield} <div class="col-sm-6"> <div class="form-group"> <label for="customfield{$customfield.id}">{$customfield.name}</label> {$customfield.input} {if $customfield.description} <span class="field-help-text"> {$customfield.description} </span> {/if} </div> </div> {/foreach} </div> </div> Any help? Thanks. Link to comment Share on other sites More sharing options...
brian! Posted February 6, 2018 Share Posted February 6, 2018 15 hours ago, DewlanceHosting said: Any help? can I give you two answers to this - a) the obvious one (and there may be reasons why this isn't valid for you) or b) the Smarty solution... a) https://docs.whmcs.com/Custom_Fields#Client_Custom_Fields Quote These can be set to Show on Order Form if you want the client to enter them or left as admin area only for private entries. The client can view and edit the field values from the client area unless they are set to admin only. any reason why you can't just untick the "Show On Order Form" checkboxes for the customfields you don't want to show ? b) you can loop through the array as normal, but you just need to add an {if} statement... {foreach $customfields as $customfield} {if $customfield.id eq '2'} <div class="col-sm-6"> <div class="form-group"> <label for="customfield{$customfield.id}">{$customfield.name}</label> {$customfield.input} {if $customfield.description} <span class="field-help-text"> {$customfield.description} </span> {/if} </div> </div> {/if} {/foreach} so the above would only show the custom field with an id value of 2. c) there would be a 3rd option of using a hook to manipulate the array... 1 Link to comment Share on other sites More sharing options...
DemoTiger Posted February 7, 2018 Author Share Posted February 7, 2018 12 hours ago, brian! said: can I give you two answers to this - a) the obvious one (and there may be reasons why this isn't valid for you) or b) the Smarty solution... a) https://docs.whmcs.com/Custom_Fields#Client_Custom_Fields any reason why you can't just untick the "Show On Order Form" checboxes for the customfields you don't want to show ? b) you can loop through the array as normal, but you just need to add an {if} statement... {foreach $customfields as $customfield} {if $customfield.id eq '2'} <div class="col-sm-6"> <div class="form-group"> <label for="customfield{$customfield.id}">{$customfield.name}</label> {$customfield.input} {if $customfield.description} <span class="field-help-text"> {$customfield.description} </span> {/if} </div> </div> {/if} {/foreach} so the above would only show the custom field with an id value of 2. c) there would be a 3rd option of using a hook to manipulate the array... a) Yes, I want to show "GST/VAT" option to only in selected country like "India". b) Thank you soooo much!! You are Great!! c) Going to use your code, Thank you again Link to comment Share on other sites More sharing options...
DemoTiger Posted February 7, 2018 Author Share Posted February 7, 2018 (edited) I use this code to remove selected custom field from order form, I filter customer by using Currency code. Customer from my selected country use "INR" currency. (Example Code - I use GBP instead of INR to show example so If anyone want to know how I display custom field then they can use it) {if $currency.code eq 'GBP'} Here paste code of {foreach $customfields as.....} (Display all Custom Fields) {else $customfields} {$customfields.1 = $different-name-here} //Replace Variable name of your customfield you wish to remove // Here paste code of {foreach $customfields as.....} (Display all Custom Fields but one of customfield.1 will be removed because of variable name was replaced before running this code) Edited February 7, 2018 by DewlanceHosting Link to comment Share on other sites More sharing options...
brian! Posted February 7, 2018 Share Posted February 7, 2018 22 minutes ago, DewlanceHosting said: I use this code to remove selected custom field from order form, I filter customer by using Currency code. Customer from my selected country use "INR" currency. that's quite clever... I had assumed you were going to do it from the country dropdown value, but that would have required jQuery to determine it. you could probably simplify it to just one loop for everyone... so in the code below, anyone using GBP will see all custom fields; those using other currencies will see them all apart from customfield id2 - if you wanted to, you could use names instead of ID, but I generally prefer IDs as they will be unique. {foreach $customfields as $customfield} {if $customfield.id neq '2' or $currency.code eq 'GBP'} <div class="col-sm-6"> <div class="form-group"> <label for="customfield{$customfield.id}">{$customfield.name}</label> {$customfield.input} {if $customfield.description} <span class="field-help-text"> {$customfield.description} </span> {/if} </div> </div> {/if} {/foreach} 1 Link to comment Share on other sites More sharing options...
DemoTiger Posted February 7, 2018 Author Share Posted February 7, 2018 Thanks.. I will try this to use less code. Link to comment Share on other sites More sharing options...
Recommended Posts