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.
Delete The “(optional)” Suffix From The WooCommerce Checkout Fields Label
You should place custom PHP in functions.php
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.
Delete The “(optional)” Suffix From The WooCommerce Checkout Fields Label
PHP:
/**
* @snippet Remove (optional) from Woo Checkout fields
* @compatible WooCommerce 9
*/
add_filter( 'woocommerce_form_field', 'gpluno_remove_optional_checkout_fields', 9999 );
function gpluno_remove_optional_checkout_fields( $field ) {
$field = preg_replace('/ <span class="optional">(.*?)<\/span>/', '', $field );
return $field;
}
You should place custom PHP in functions.php