0

I'm trying to disable shipping methods based on the customer's email in the checkout page. My state code validation works but not my email validation. When I type the testing email in the textfield it updates the cart total where the shipping methods are but they're not being hidden. What am I doing wrong on the email part?

This is the state code:

add_action( 'woocommerce_package_rates', 'validate_state', 100, 2 );
function validate_state( $rates, $package ) {

   $customer_data = WC()->session->get('customer');
   $state = $customer_data['state'];

   if ( $state != "AB" ) {
      unset( $rates['100'] );
      unset( $rates['300'] );
   }

   return $rates;
}

add_action( 'woocommerce_checkout_fields', 'update_field_on_change' );
function update_field_on_change( $fields ) {

   $fields['billing']['billing_state']['class'][] = 'update_totals_on_change';

   return $fields;
}

This is the email code:

add_action( 'woocommerce_package_rates', 'validate_email', 100, 2 );
function validate_email( $rates, $package ) {

   $customer_data = WC()->session->get('customer');
   $email = $customer_data['email'];

   if ( $email != "test@gmail.com" ) {
      unset( $rates['100'] );
      unset( $rates['300'] );
   }

   return $rates;
}

add_action( 'woocommerce_checkout_fields', 'update_field_on_change' );
function update_field_on_change( $fields ) {

   $fields['billing']['billing_email']['class'][] = 'update_totals_on_change';

   return $fields;
}
Renz
  • 1
  • 2

0 Answers0