What can we help you with?
Remove the (optional) Text from WooCommerce Checkout Fields
There may be instances where you want to remove or hide the Optional text from the WooCommerce Checkout fields. To do this, ELEX has provided a simple code snippet. This is a generic code snippet and works regardless of any third-party plugins.
Code snippet to Remove the (optional) Text from WooCommerce Checkout Fields
The below screenshot shows the default settings where the “optional” text is added to Company Name and Phone Number field.
Add the below code snippet in the Theme Functions (functions.php) file of your activated website theme.
add_filter( 'woocommerce_form_field' , 'elex_remove_checkout_optional_text', 10, 4 ); function elex_remove_checkout_optional_text( $field, $key, $args, $value ) { if( is_checkout() && ! is_wc_endpoint_url() ) { $optional = ' <span class="optional">(' . esc_html__( 'optional', 'woocommerce' ) . ')</span>'; $field = str_replace( $optional, '', $field ); } return $field; }
After you have saved the file, the updated checkout page will be as shown in the screenshot below.
Explore our blog section for more related articles.
You can also check out WooCommerce and WordPress plugins in ELEX.
2 Comments. Leave new
Hi,
I found your solution for hiding the (optional) text on the Checkout page and it works great.
But, this same (optional) text still remains in My Account>Addresses.for Billing and Shipping addresses.
Will you be posting a snippet to hide this also? I’m sure many others will appreciate another snippet to remove these.
Thank you!
Hello, Please find the snippet here:
add_filter( ‘woocommerce_form_field’ , ‘elex_remove_checkout_optional_text’, 10, 4 );
function elex_remove_checkout_optional_text( $field, $key, $args, $value ) {
$optional = ‘ (‘ . esc_html__( ‘optional’, ‘woocommerce’ ) . ‘)‘;
$field = str_replace( $optional, ”, $field );
return $field;
}