Unset COD Payment Gateway on the Basis of Post Code in Woocommerce
₹600-1500 INR
Avslutat
Publicerad nästan fem år sedan
₹600-1500 INR
Betalning vid leverans
I need to unset Cash on Delivery payment gateway on the basis of post code entered by the customer on checkout page. Currently, I have created a shipping zone with the list of pincoedes and I am using the following function to unset the gateway:
function conditionally_remove_payment_methods( $gateways ){
// Define Zone Check for Pincode
$targeted_zones_names = array('All','Zone 4','Zone 7');
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); // The chosen shipping mehod
$chosen_method = explode(':', reset($chosen_methods) );
$shipping_zone = WC_Shipping_Zones::get_zone_by( 'instance_id', $chosen_method[1] );
$current_zone_name = $shipping_zone->get_zone_name();
if( in_array( $current_zone_name, $targeted_zones_names ) && WC()->customer->get_billing_postcode() <> ''){
unset( $gateways['cod'] );
}
return $gateways;
}
The number of pincodes entered in the shipping zone is around 15,000. This is causing the checkout page to load in 25 seconds or more. I need a way to accomplish this without slowing down the checkout page loading.