News:

Support the VirtueMart project and become a member

Main Menu

programmatically change shopper field validation

Started by D_L_I, November 08, 2021, 09:48:45 AM

Previous topic - Next topic

D_L_I

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?

Studio 42

You have to write your own userfield plugin to do that

D_L_I

Thanks.
can you please point me to an example or documentation for that?

Studio 42

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';


   }