Created
March 24, 2015 09:35
-
-
Save DriesS/71664f4ffb70dfde3cfa to your computer and use it in GitHub Desktop.
Code vat check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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