Support » Plugin: WooCommerce EU VAT Assistant » Removing the country field (and VAT related fields) for certain products

  • Resolved freekwp


    Hi Diego,

    First things first: awesome plugin!

    I’m looking to hide the #billing_country_field for certain products. I have a few free digital products (courses) and want to make the checkout page as short as possible for them. (Avoiding the checkout process altogether is not an option, because customers still need to create an account to be enrolled in the course.)

    I know how I can remove the country field for those free products using a filter. But because the country field is removed, the VAT self-certification field appears, because there is insufficient evidence. (Sidenote: the VAT number field is set to ‘hidden’ so isn’t relevant.)

    What would be the best way to handle this situation?

    I’ve read this thread from two years ago:

    Would you still say it’s not a good idea to remove fields using PHP?

    Would it perhaps be possible to set the self-certification option to ‘never’, only for certain products?

    Would appreciate any thoughts you might have on this!

    Cheers, Freek

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


    The self-certification is an element that applies to a customer, not to products. Due to that, you can’t enable or disable it on a per-product basis.

    If you wish to remove the VAT number ans self-certification field, you can do that by writing a filter for hook woocommerce_checkout_fields and remove the unwanted fields as you like (e.g. when the cart total is zero).

    The fields added by the EU VAT Assistant are the following:

    1. $fields[‘billing’][‘vat_number’]
    2. $fields[‘billing’][‘customer_location_self_certified’]

    Please just note that, if you remove the fields that way, then the checkout page won’t work as you expect in the following scenario:

    1. Add a free product to the cart.
    2. Go to the checkout page. The page will be missing the fields you removed.
    3. Open another tab.
    4. Add a paid product to the cart.
    5. Go back to the checkout page in the first tab and change the address. The totals will refresh via Ajax and will no longer be zero, but the billing country, VAT number and self-certification fields will not appear anyway, because your custom code removed them when the checkout page was loaded.

    Due to the above, I would recommend to test your custom code thoroughly, to make sure that it works as you need.

    Thanks Diego! Very helpful, I managed to figure it out. Thanks also for the heads up – I think my set up will probably be fine, because I only allow one product to be in the cart at a time, but I’ll be sure to test it thoroughly.

    For some reason, I could not remove the fields using a filter. (Works perfectly for other fields, just not the two Aelia fields.) So instead, I tweaked your code from the linked thread above and changed the setting for self-certification when the cart total is 0. Is there any reason this way of doing it might run into issues?

    If anyone else wants to achieve this, this is the code I used.

    // Remove the country field when cart total is 0
    function custom_remove_country_checkout_field( $fields ) {
    		if(WC()->cart->total <= 0) {
    		return $fields;
    add_filter( 'woocommerce_checkout_fields' , 'custom_remove_country_checkout_field' );
    // Remove self-certification field when cart total is 0
    add_filter('wc_aelia_eu_vat_assistant_show_checkout_field_self_certification', function($show_self_certification_field_setting, $country) {
    	  if(WC()->cart->total <= 0) {
        	$show_self_certification_field_setting = false;
      return $show_self_certification_field_setting;
    }, 10, 2);
    Plugin Author Diego


    The only case in which I think that you might encounter some issues is the one I described earlier, i.e. if the cart total changes after the checkout page is loaded.

    Regarding the filter, the reason why your logic to remove the fields didn’t work is most likely the same one described here:

    Diego 3 weeks, 1 day ago
    Please note that the EU VAT Assistant adds the fields by using a filter with a priority of 40. You will have to specify a priority of 41 or higher, to alter the fields added by the plugin (e.g. add_filter('woocommerce_checkout_fields', 'custom_override_checkout_fields', 50);

    Thanks Diego! I’ll be sure to test for that.

    I appreciate all your help!

    Hi Diego,

    On testing, it appears it is not possible to complete orders. I’m getting the following message:

    “Unfortunately, we could not collect sufficient information to confirm your location. To proceed with the order, please tick the box below the billing details to confirm that you will be using the product(s) in country you selected.”

    So it appears that the plugin is doing its job quite well, just a bit too well in this particular case. Is there a way to disable this ‘check’ if there is enough information?


    Plugin Author Diego


    If you configured the EU VAT Assistant to require the self-certification in case of insufficient evidence, then it’s doing the right thing by blocking the order when that is the case. There isn’t a filter to skip that validation altogether, as that would defeat the option to make it required, but you can work around it by implementing a filter for hook wc_aelia_eu_vat_assistant_location_evidence_countries. You should return an array of country codes, and as long as the array contains the same code twice, or more, the self-certification check will be skipped.

    Please note that all we discussed is abundantly outside the scope of our support service. Customisations, like the one you are trying to implement, fall under the scope of consultations. If you need assistance with the implementation, please feel free to contact us.

    Thanks Diego, I managed to get it all sorted.

    I realise this is beyond ‘normal’ support, which makes me appreciate your help all the more. Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Removing the country field (and VAT related fields) for certain products’ is closed to new replies.