If a WooCommerce checkout field is set to “not required“, its label will get the “(optional)” suffix. Considering the required fields get the red “*” suffix, you may want to get completely rid of the (optional) string.
Sure, you could be using CSS to hide it… but as usual this is not ideal. With CSS display:none, the string loads and then you hide it; with PHP you avoid the loading in the first place.
So, let’s see how this is done – this snippet is also running on this same website so it should definitely work!
PHP Snippet: Delete The “(optional)” Suffix From The WooCommerce Checkout Fields Label
/**
* @snippet Remove (optional) from Woo Checkout fields
* @tutorial Get CustomizeWoo.com FREE
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 9
* @community Join https://businessbloomer.com/club/
*/
add_filter( 'woocommerce_form_field', 'bbloomer_remove_optional_checkout_fields', 9999 );
function bbloomer_remove_optional_checkout_fields( $field ) {
$field = preg_replace('/ <span class="optional">(.*?)<\/span>/', '', $field );
return $field;
}
Great Rodolfo!!!, now it’s minimalist. It was very annoying.
Big!! 🙂
Thank you!