Skip to content

Instantly share code, notes, and snippets.

@NorthTexasCreative
Created October 25, 2022 21:22
Show Gist options
  • Save NorthTexasCreative/33fd82f3cf54c8f1561cdb5e65fecd2b to your computer and use it in GitHub Desktop.
Save NorthTexasCreative/33fd82f3cf54c8f1561cdb5e65fecd2b to your computer and use it in GitHub Desktop.
WooCommerce Required Fields
/** 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