1

I've two shipping methods

  1. Pickup
  2. Delivery

If Pickup is selected - billing_postcode field in checkout must be hidden.

If Delivery selected - billing_postcode should be displayed.

I've tried this snippet

add_filter('woocommerce_checkout_fields', 'xa_remove_billing_checkout_fields');

function xa_remove_billing_checkout_fields($fields) {
$shipping_method ='local_pickup:6'; // Value of the applicable shipping method.
global $woocommerce;
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];

if ($chosen_shipping == $shipping_method) {
unset($fields['billing']['billing_postcode']); 
}
return $fields;
}

It works only when I force reload the page. I've tried to clear the site cache but it didn't helped me. Kindly help me to resolve this. Waiting for response with hope.

0 Answers0