Method 1: using CSS
.woocommerce form .form-row .required{ display: none ; } .woocommerce form .form-row .optional{ display: none ; }
Method 2: using a PHP snippet. The code goes in function.php file of your active child theme (or active theme).
// PHP: Remove "(optional)" from our non required fields add_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 fields add_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 }
Source: StackOverflow
Leave a Reply