function commerce_avatax_exemptions_form_alter in Drupal Commerce Connector for AvaTax 7.4
Implements hook_form_alter().
File
- modules/
commerce_avatax_exemptions/ commerce_avatax_exemptions.module, line 25 - Commerce AvaTax Exemptions.
Code
function commerce_avatax_exemptions_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'commerce_checkout_form_checkout') {
$order = $form_state['order'];
$account = user_load($order->uid);
$role_intersect = array_intersect(variable_get('commerce_avatax_exemptions_roles', array(
1,
)), array_keys($account->roles));
if (empty($role_intersect)) {
return;
}
$form['#prefix'] = '<div id="checkout_form">';
$form['#suffix'] = '</div>';
$profile_type = strtolower(variable_get('commerce_avatax_tax_address', 'Shipping'));
if (isset($form['customer_profile_shipping']['commerce_customer_profile_copy']['#default_value'])) {
if ($form['customer_profile_shipping']['commerce_customer_profile_copy']['#default_value']) {
$profile_type = 'billing';
}
}
if (isset($form['customer_profile_' . $profile_type]['commerce_customer_address'][LANGUAGE_NONE][0]['locality_block']['administrative_area'])) {
$form['customer_profile_' . $profile_type]['commerce_customer_address'][LANGUAGE_NONE][0]['locality_block']['administrative_area']['#ajax'] = array(
'wrapper' => 'checkout_form',
'callback' => 'commerce_avatax_exemptions_checkout_form_ajax_callback',
);
}
$state = '';
if (isset($form['customer_profile_' . $profile_type]['commerce_customer_address'][LANGUAGE_NONE][0])) {
$state = $form['customer_profile_' . $profile_type]['commerce_customer_address'][LANGUAGE_NONE][0]['#address']['administrative_area'];
}
$states = variable_get('commerce_avatax_exemptions_states', array());
if (!$states || $state && in_array($state, $states)) {
$form['commerce_avatax_exemptions']['#access'] = TRUE;
}
}
}