Reputation: 3197
I'm removing specific Woocoomerce checkout fields, as they are not required for pick up orders.
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_state']);
unset($fields['order']['order_comments']);
return $fields;
}
This works great to remove the fields but doesn't allow me to checkout. I receive the following error:
I've also tried to change the required array item to FALSE, to no avail.
$fields['billing']['billing_company']['required'] = false;
$fields['billing']['billing_address_1']['required'] = false;
$fields['billing']['billing_address_2']['required'] = false;
$fields['billing']['billing_city']['required'] = false;
$fields['billing']['billing_postcode']['required'] = false;
$fields['billing']['billing_country']['required'] = false;
$fields['billing']['billing_state']['required'] = false;
I'm using the Storefront theme as well as Woocommerce 3.1.2
Upvotes: 0
Views: 2657
Reputation: 1
Similar problem with "unset field", so just try set priority to "100" or like that example: add_filter('woocommerce_checkout_fields', 'checkout_fields', 100);
Source:
if(!function_exists('checkout_fields')){
function checkout_fields($fields){
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_state']);
return $fields;
}
add_filter('woocommerce_checkout_fields', 'checkout_fields', 100);
}
Upvotes: 0
Reputation: 1437
It is an annoying thing in Woocommerce after version 3. Either downgrade to earlier version or allow those details through especially country. You can use css or JS to hide the form input but set the needed country in the woocommerce settings.
Upvotes: 1