Created
June 24, 2023 17:57
-
-
Save stavrossk/5d1f29616fce9a7baa9f97f8495ae200 to your computer and use it in GitHub Desktop.
WooCommerce Filter Hook to Make checkout addresses fields not required in WooCommerce. All code goes in functions.php file of your active child theme.
This file contains hidden or 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
// Billing and shipping addresses fields | |
add_filter( 'woocommerce_default_address_fields' , 'filter_default_address_fields', 20, 1 ); | |
function filter_default_address_fields( $address_fields ) | |
{ | |
// Only on checkout page | |
if( ! is_checkout() ) return $address_fields; | |
// All field keys in this array | |
$key_fields = array('country','first_name','last_name','company','address_1','address_2','city','state','postcode'); | |
// Loop through each address fields (billing and shipping) | |
foreach( $key_fields as $key_field ) | |
$address_fields[$key_field]['required'] = false; | |
return $address_fields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment