• Resolved christianserrer

    (@christianserrer)


    Hello everyone,

    on our website we would like to implement a eu vat number field with a validation of the vat number, so that the customer can only place the purchase if the vat numbere is valid. The only problem we are having is that the field should be conditional on the products that are in the cart. So it should only appear if some specific products are in the cart.

    Is that possible with this plugin and if it is, can you please assist us which code we have to use for a conditional field with this plugin.

    Many thanks,
    Christian

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Diego

    (@daigo75)

    Hi Christian,
    The EU VAT Assistant provides a hook called wc_aelia_eu_vat_assistant_show_vat_field. If you write a filter for that hook, you can return false when the VAT number should not be displayed, and it won’t appear on the checkout page.

    Note
    If you show or hide the VAT field, and the cart contents change while the checkout page is open (e.g. if the customer adds products from another tab), the VAT field will stay as it is. This is because the field is displayed when the page is loade. The checkout page can refresh some sections using Ajax, and the billing section, where the VAT field is located, is not amongst them. Refreshing the checkout page would update the VAT field too.

    If you need to handle the condition in which the cart could change while the checkout page stays open, then you might want to use a different approach, and show/hide the VAT field using JavaScript. That’s more complex, as you would have to intercept the “checkout refresh” event, determine what the cart contents are, then show or hide the VAT number on the checkout page accordingly.

    Should you need assistance implementing this customisation, please feel free to contact us (https://aelia.co/contact). We can review your requirements and prepare an estimate to implement a solution for you.

    Plugin Author Diego

    (@daigo75)

    Update
    Filter wc_aelia_eu_vat_assistant_show_vat_field has now been replaced by wc_aelia_eu_vat_assistant_show_checkout_field_vat_number. It can be used the same way (example below).

    
    add_filter('wc_aelia_eu_vat_assistant_show_checkout_field_vat_number', function($show_field, $is_field_required) {
      // Set $show_field to true or false, depending on your custom
      // conditions
      return $show_field;
    }, 10, 2);
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Conditional eu vat number checkout field’ is closed to new replies.