How to Covert Attributes of Checkout Address Fields based on Shipping Method
-
Hi all. I’m facing a very difficult situation right now and hope someone can give some useful solutions on this one. I’m using a 3rd party plugin developed by the domestic payment flow company which provides visitors to pay by credit cards and common logistics options. The shipping method is named “ecpay_shipping”.
I’d like to convert the required address related fields to optional and hide them on the condition that
shipping_method
equalsecpay_shipping
.The four fields I wish to tweak are:
- billing_address_1
- billing_city
- billing_postcode
- billing_state
I have tried the followed function but it only does the hiding part but causes the order process to drop because the four fields are not filled properly.
add_filter('woocommerce_checkout_fields', 'xa_remove_billing_checkout_fields'); function xa_remove_billing_checkout_fields($fields) { $shipping_method ='ecpay_shipping'; global $woocommerce; $chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); $chosen_shipping = $chosen_methods[0]; if ($chosen_shipping == $shipping_method) { unset($fields['billing']['billing_address_1']); unset($fields['billing']['billing_city']); unset($fields['billing']['billing_postcode']); unset($fields['billing']['billing_state']); } return $fields; }
Kinda stuck on this. Hopefully, someone can come up with a solution to this. Thank you in advance.
- The topic ‘How to Covert Attributes of Checkout Address Fields based on Shipping Method’ is closed to new replies.