Remove "(optional)" text from checkout fields in Woocommerce 3.4+
Update 2
To remove "(optional)" text from checkout fields labels introduced with Woocommerce release 3.4, just as it was before, you will need to add the following code:
// PHP: Remove "(optional)" from our non required fieldsadd_filter( 'woocommerce_form_field' , 'remove_checkout_optional_fields_label', 10, 4 );function remove_checkout_optional_fields_label( $field, $key, $args, $value ) { // Only on checkout page if( is_checkout() && ! is_wc_endpoint_url() ) { $optional = ' <span class="optional">(' . esc_html__( 'optional', 'woocommerce' ) . ')</span>'; $field = str_replace( $optional, '', $field ); } return $field;}// JQuery: Needed for checkout fields to Remove "(optional)" from our non required fieldsadd_filter( 'wp_footer' , 'remove_checkout_optional_fields_label_script' );function remove_checkout_optional_fields_label_script() { // Only on checkout page if( ! ( is_checkout() && ! is_wc_endpoint_url() ) ) return; $optional = ' <span class="optional">(' . esc_html__( 'optional', 'woocommerce' ) . ')</span>'; ?> <script> jQuery(function($){ // On "update" checkout form event $(document.body).on('update_checkout', function(){ $('#billing_country_field label > .optional').remove(); $('#billing_address_1_field label > .optional').remove(); $('#billing_postcode_field label > .optional').remove(); $('#billing_state_field label > .optional').remove(); $('#shipping_country_field label > .optional').remove(); $('#shipping_address_1_field label > .optional').remove(); $('#shipping_postcode_field label > .optional').remove(); $('#shipping_state_field label > .optional').remove(); }); }); </script> <?php}
Code goes in function.php file of your active child theme (or active theme). Tested and works in Woocommerce version 3.4+.
You could merge the included jQuery code with your existing jQuery code…
you can easily use css in this
.woocommerce form .form-row .required{ display: none ;}.woocommerce form .form-row .optional{ display: none ;}
A better solution:
/** * Remove optional label * https://elextensions.com/knowledge-base/remove-optional-text-woocommerce-checkout-fields/ */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;}