Hello,
I wish to add a field on my checkout form that will be shown and required only when certain products are in the cart.
How can I programmatically set a field to be required?
You have to write your own userfield plugin to do that
Thanks.
can you please point me to an example or documentation for that?
No doc exist and to long to explain all if you never wrote a plugin before
The front display trigger is
public function plgVmOnUserfieldDisplay($_prefix, $field, $user_id, &$return ){
if ('plugin' . $this->_name != $field->type) {
return;
}
//you need to get the cart and loop the products in cart
$selected = $return['fields'][$field->name]['value']; // the default or current value
$return['fields'][$field->name]['formcode'] = 'what you need to render';
}