Jump to content

Prefill product custom field


arturgornik

Recommended Posts

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. :idea:

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. :idea:

 

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}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated