Created
October 25, 2022 21:22
-
-
Save NorthTexasCreative/33fd82f3cf54c8f1561cdb5e65fecd2b to your computer and use it in GitHub Desktop.
WooCommerce Required Fields
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
/** Change obligatory-optional status on billing fields | |
* true = required | |
* false = optional | |
*/ | |
add_filter('woocommerce_billing_fields', 'force_billing_fields', 1000, 1); | |
function force_billing_fields($fields) { | |
$fields['billing_first_name']['required'] = false; //First Name | |
$fields['billing_last_name']['required'] = false; //Last Name | |
$fields['billing_email']['required'] = false; //Email | |
$fields['billing_phone']['required'] = false; //Phone number | |
return $fields; | |
} | |
/** Other billing fields | |
* true = required | |
* false = optional | |
*/ | |
add_filter( 'woocommerce_default_address_fields', 'customize_extra_fields', 1000, 1 ); | |
function customize_extra_fields( $address_fields ) { | |
$address_fields['company']['required'] = true; //Company name | |
$address_fields['address_1']['required'] = false; //Address | |
$address_fields['country']['required'] = false; //Country | |
$address_fields['city']['required'] = false; //City | |
$address_fields['state']['required'] = false; //State | |
$address_fields['postcode']['required'] = false; //Postcode | |
return $address_fields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment