Skip to content

Instantly share code, notes, and snippets.

@DriesS
Created March 24, 2015 09:35
Show Gist options
  • Save DriesS/71664f4ffb70dfde3cfa to your computer and use it in GitHub Desktop.
Save DriesS/71664f4ffb70dfde3cfa to your computer and use it in GitHub Desktop.
Code vat check
/**
* Custom validation for the customer_profile_billing checkout pane.
*/
function arkaos_glue_commerce_checkout_form_validate($form, &$form_state, $checkout_pane, $order) {
$valid = TRUE;
// check vat
$vat = $form_state['values']['customer_profile_company_info']['field_vat_number']['und'][0]['vat_number'];
$country = $form_state['values']['customer_profile_billing']['commerce_customer_address']['und'][0]['country'];
if(!empty($vat) && strtoupper(substr($vat,0,2)) !== $country) {
form_set_error('customer_profile_company_info][field_vat_number][und][0][vat_number',t('This VAT number does not match the billing address you provided.'));
$valid = FALSE;
}
// Function must return TRUE or FALSE, not just set a form error.
// Again, see http://drupal.org/node/1796488
return $valid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment