Last active
March 12, 2020 10:45
-
-
Save xadapter/a583b512feeeb25a1ff00b62dc2593af to your computer and use it in GitHub Desktop.
Snippet to hide the checkout field(s) based on the WooCommerce shipping method. Supports PluginHive Shipping Plugins: https://www.pluginhive.com/product-category/woocommerce-plugin/woocommerce-shipping/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('woocommerce_checkout_fields', 'xa_remove_billing_checkout_fields'); | |
function xa_remove_billing_checkout_fields($fields) { | |
$shipping_method ='free_shipping:1'; // Set the desired shipping method to hide the checkout field(s). | |
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']); // Add/change filed name to be hide | |
unset($fields['billing']['billing_address_2']); | |
} | |
return $fields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment