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.

Remove the (optional) Text from WooCommerce Checkout Fields | Default Settings

Default Settings

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 = '&nbsp;<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.

Remove the (optional) Text from WooCommerce Checkout Fields | The "Optional" text removed

The “Optional” text removed

 


Explore our blog section for more related articles.

You can also check out WooCommerce and WordPress plugins in ELEX.

Previous Hide Checkout Fields Based on the Shipping Method: WooCommerce (With Video)
Next How to hide or disable a WooCommerce shipping service? (Code Snippets)

2 Comments

  1. wpuser123
    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!
    • ELEXtensions
      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; }

Leave a Reply

WordPress Image Lightbox Plugin