Code-Snippets-Functions/Execute a function on a child site/WooCommerce/remove-billing-checkout-fields-by-shipping-method.txt

14 lines
606 B
Text

add_filter('woocommerce_checkout_fields', 'wc_remove_billing_checkout_fields');
function wc_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;
}