4

Can someone guide me on how to keep VAT field visible and required for non-USA countries and hide and not require for USA country on checkout page add address ?

I tried this way but its not working

require(['jquery'],function($){
jQuery( document ).ready(function() {
    jQuery('#co-shipping-form div[name="shippingAddress.country_id"] select').change(function(){
        var cnt = jQuery(this).val();
        if ( cnt == 'US'){
            jQuery('#co-shipping-form [name="shippingAddress.vat_id"]').hide();
        }else{
            jQuery('#co-shipping-form [name="shippingAddress.vat_id"]').show();
        }
    });
}); 
});

Thanks

7
  • jQuery('#co-shipping-form div[name="shippingAddress.country_id"] select') its seems you are using wrong selector. can you add your html?
    – Sathish
    Aug 28, 2017 at 13:18
  • Its default Magento2 checkout page , add new address . FYI , When i run this script in console , its working fine Aug 28, 2017 at 13:22
  • Is there any VAT for the USA? Aug 31, 2017 at 11:53
  • > I get your code and it's work but after any change on country_id > select. When I removed jQuery( document ).ready(function() { it's > working also on first load. > > require(['jquery'],function($){ > jQuery('#co-shipping-form div[name="shippingAddress.country_id"] select').change(function(){ > var cnt = jQuery(this).val(); > if (cnt == 'US'){ > jQuery('#co-shipping-form [name="shippingAddress.vat_id"]').hide(); > }else{ > jQuery('#co-shipping-form [name="shippingAddress.vat_id"]').show(); > } > }); }); It's not working. You musst need to update the JsLayout Proccessor via plugin. Oct 10, 2018 at 15:36
  • This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From Review Oct 10, 2018 at 16:11

1 Answer 1

1

I get your code and it's work but after any change on country_id select.

When I removed jQuery( document ).ready(function() { it's working also on first load.

require(['jquery'],function($){
    jQuery('#co-shipping-form div[name="shippingAddress.country_id"] select').change(function(){
        var cnt = jQuery(this).val();
        if (cnt == 'US'){
            jQuery('#co-shipping-form [name="shippingAddress.vat_id"]').hide();
        }else{
            jQuery('#co-shipping-form [name="shippingAddress.vat_id"]').show();
        }
    });
});

There is also second option, little more complex. You need to create 2 stores:

  • first for US where you will disable VAT
  • second for non US where you enable VAT

Option are availabe on:

  • Catalog
    • Customer Configuration
      • Create New Account Options
        • Show VAT Number on Storefront.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.