Remove the (optional) Text from WooCommerce Checkout Fields

You are here:

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.

    Leave a Reply

    WordPress Image Lightbox Plugin