Author Topic: programmatically change shopper field validation  (Read 272 times)

D_L_I

  • Beginner
  • *
  • Posts: 22
programmatically change shopper field validation
« on: November 08, 2021, 09:48:45 am »
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

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4522
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: programmatically change shopper field validation
« Reply #1 on: November 08, 2021, 11:01:40 am »
You have to write your own userfield plugin to do that

D_L_I

  • Beginner
  • *
  • Posts: 22
Re: programmatically change shopper field validation
« Reply #2 on: November 09, 2021, 08:05:15 am »
Thanks.
can you please point me to an example or documentation for that?

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4522
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: programmatically change shopper field validation
« Reply #3 on: November 09, 2021, 11:55:47 am »
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';


   }