How to Change Woocommerce "Sort By" Text?
I hope better way to solve your problem. Just copy and paste your theme of functions.php. Okay
add_filter('woocommerce_catalog_orderby', 'wc_customize_product_sorting');function wc_customize_product_sorting($sorting_options){ $sorting_options = array( 'menu_order' => __( 'Sorting', 'woocommerce' ), 'popularity' => __( 'Sort by popularity', 'woocommerce' ), 'rating' => __( 'Sort by average rating', 'woocommerce' ), 'date' => __( 'Sort by newness', 'woocommerce' ), 'price' => __( 'Sort by price: low to high', 'woocommerce' ), 'price-desc' => __( 'Sort by price: high to low', 'woocommerce' ), ); return $sorting_options;}
Here's how you can change the options of the orderby via the woocommerce_catalog_orderby
filter.
add_filter( 'woocommerce_catalog_orderby', 'so_37445423_orderby_options', 20 );function so_37445423_orderby_options( $options ){ $options['menu_order'] = __('Sort the normal way', 'your-child-theme'); return $options;}
I've added the 20 priority, because I'm guessing that your theme is already filtering this and/or hard-coding them into the orderby.php
template. I'm guessing this because the default WooCommerce has "Default sorting" instead of "Sort by Default". "Sort by name" is also not a part of core.
Add this to your themes function.php . Change the translation according to your requirement.
add_filter( 'gettext', 'theme_sort_change', 20, 3 );function theme_sort_change( $translated_text, $text, $domain ) { if ( is_woocommerce() ) { switch ( $translated_text ) { case 'Sort by newness' : $translated_text = __( 'Sort by Newest', 'theme_text_domain' ); break; } } return $translated_text;}
Reference : https://wordpress.org/support/topic/change-woocommerce-sort-by-text