• globalmanager46

    (@globalmanager46)


    Hello,

    I’m trying to show the EU VAT field for specific products only

    I tried several code snippets, but all failed and break my site

    Here is the last i tried, could you tell me how i could achieve this correctly please? I have 10 products which i need to have this field shown, for all other other i don’t need it.

    add_filter(‘wc_aelia_eu_vat_assistant_show_checkout_field_vat_number’, function($show_field, $is_field_required) {
    foreach( WC()->cart->get_cart() as $cart_item ){
    $product_id = $cart_item[‘product_id’];

    if( $product_id == 5232 ) {
    $show_field = true;
    }

    return $show_field;
    }, 10, 2);`

    Thanks a lot in advance

    Best Regards

Viewing 1 replies (of 1 total)
  • Plugin Author Diego

    (@daigo75)

    By the look of it, your code is doing the following:
    – If a condition is satisfied, set $show_field to true.
    – Else, leave $show_field as it is (which, most likely, means leave it set to true).
    The result is that the field is always displayed.

    If you’re looking to hide the field, you should set $show_field to false when the condition is not satisfied.

    Customisations like the one you need are outside the scope of our support service, therefore we won’t be test your code or rewrite it for you, but you can use the following template to get started:

    add_filter('wc_aelia_eu_vat_assistant_show_checkout_field_vat_number', function($show_field, $is_field_required) {
      // Replace "<SOME CONDITION IS NOT SATISFIED>" with the actual check, e.g. to
      // see if the products do NOT fall into the list that need the VAT number
      if(<SOME CONDITION IS NOT SATISFIED>) {
        $show_field = false;
      }
      return $show_field;
    }, 10, 2);
    • This reply was modified 3 years ago by Diego. Reason: Added tags
Viewing 1 replies (of 1 total)
  • The topic ‘EU VAT field for specific products’ is closed to new replies.