arturgornik Posted August 8, 2017 Share Posted August 8, 2017 Hi, I'm lookin for solution how to prefill product custom field. Best option will be the hook but I can't find proper one. Hook because I need to calculate prefilled value (ex. small PHP code), it is not the same value every time. Could you help, please? Artur 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 8, 2017 Share Posted August 8, 2017 prefill during ordering ? then I suppose it would be clientareapagecart, take the $customfields array, loop through it and edit $customfield.input to include your value for this particular PCF. personally, i'd find it quicker to do it in the template using Smarty (apart from calc, it would just be one line), but if you already have your PHP to calculate the value, then you might as well use a hook. 0 Quote Link to comment Share on other sites More sharing options...
arturgornik Posted August 9, 2017 Author Share Posted August 9, 2017 Hi, I've tried something like that: <?php add_hook('ClientAreaPageCart', 1, function($vars) { // Perform hook code here... echo "Hello WORLD!"; foreach ($customfields as $key => $value) { echo "{$key} => {$value} "; }; }); to see what's inside $customfields but nothing is shown. Could you be more detailed how to do that please? Thanks Artur 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 10, 2017 Share Posted August 10, 2017 to see what's inside $customfields but nothing is shown.Could you be more detailed how to do that please? remember that $customfields is actually an array of arrays, so you could do what you're trying by... <?php add_hook('ClientAreaPageCart', 1, function($vars) { // Perform hook code here... echo "Hello WORLD!<br />"; $customfields = $vars['customfields']; foreach ($customfields as $key => $value) { foreach ($value as $title => $value2) { echo "{$title} => {$value2}<br />"; } }; }); though at the very least, you'd need to write it to only work on configureproduct... but frankly, you could add {debug} to the template and get those details more easily. and remember when I said it was one line of Smarty code (apart from calculation), you just change... {$customfield.input} to {if $customfield.id eq '21'}{$customfield.input|replace:'value=""':'value="brian"'}{else}{$customfield.input}{/if} remembering to change the ID value to one suitable for your circumstances.... boom - custom field pre-filled... done!. then if/when you have a calculation, assign it to a variable and use... {if $customfield.id eq '21'}{$customfield.input|replace:'value=""':'value="{$variable}"'}{else}{$customfield.input}{/if} 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.