How do I exclude a country so that the VAT number field on the checkout page only shows for certain countries?

Comments

dwkitchen’s picture

Status: Active » Fixed

You can use rules to control the display of a checkout pane with http://drupal.org/project/commerce_rules_extra

Egan7’s picture

Priority: Minor » Major
Status: Fixed » Active
dwkitchen’s picture

Priority: Major » Normal

Hi,

Please explain why you have changed the status back and set to active?

The does depend on how you are using the VAT Number field. If you are adding it to the existing billing or shipping customer profiles you could try the Conditional Fields module. However I would recommend creating a new customer profile type just for the VAT number (and possibly and other business information).

You can control the display of the Tax Customer Profile using the above mentioned module.

You will also need to check that the country of the VAT number provided matches that of the shipping destination.

dwkitchen’s picture

This code might also help.

function commerce_eu_vat_rc_form_commerce_checkout_form_checkout_alter(&$form, $form_state, $form_id) {
  if (isset($form['customer_profile_eu_vat_rc'])){
    $eu_countries = _commerce_eu_vat_eu_countries();
    $visible_conditions = array();
    foreach($eu_countries as $iso => $name){
      $visible_conditions[]['value'] = $iso;
    }
    $form['customer_profile_eu_vat_rc']['#states'] = array(
      'visible' => array(
        ':input[name="customer_profile_billing[commerce_customer_address][und][0][country]"]' => $visible_conditions,
      ),
    );
  }
}
Egan7’s picture

Hi dwkitchen,

Sorry it has been so long. Firstly my page was cached when I changed the setting on this query, then your comment came up. since then I have had to work on other areas, then I got the flu so its been a while.

I have tried all above methods except for the code. Basically we are planning to sell electronic goods so there is no supplier nor shipping methods. The rules on VAT are thus different. What we want is for EU countries to pay VAT (unless they have a VAT number). The exception to this rule is the UK where they pay VAT despite having a number.

Thus rather than adding to the code to negate a country, surely it would be easier to manipulate the code that lists the 'EU' countries and comment out the UK (GB) as if the UK was not an EU country. I tried this in the .module file but the VAT field still appears. when UK is selected as the country in the Billing information. What is causing that to appear?

Perhaps the code above works but there is an undefined function in it: _commerce_eu_vat_eu_countries()
Perhaps this function denotes the EU countries and manipulating that would work?

Thanks

dwkitchen’s picture

Status: Active » Fixed

Consider using the Commerce EU VAT module for a quick EU VAT setup that covers digital products.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.