Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active March 12, 2020 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xadapter/a583b512feeeb25a1ff00b62dc2593af to your computer and use it in GitHub Desktop.
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/
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