如何在最新版Woocommerce中更改此文本 -
答案 0 :(得分:5)
我希望更好的方法来解决你的问题。只需复制并粘贴您的functions.php主题即可。好
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;
}
答案 1 :(得分:3)
将此添加到您的主题function.php。根据您的要求更改翻译。
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;
}
参考:https://wordpress.org/support/topic/change-woocommerce-sort-by-text
答案 2 :(得分:2)
以下是如何通过woocommerce_catalog_orderby
过滤器更改orderby的选项。
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;
}
我已经添加了20个优先级,因为我猜测您的主题已经过滤了这个和/或将它们硬编码到orderby.php
模板中。我猜这是因为默认的WooCommerce有"默认排序"而不是"默认排序"。 "按名称排序"也不是核心的一部分。
答案 3 :(得分:0)
对于那些正在寻找2017-2018(版本4.9.1)的解决方案的人......
wp-content>插件> woocommerce>包括> WC-模板的functions.php
搜索:"功能woocommerce_catalog_ordering()"。这是第831行。
'menu_order' => __( 'Default 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' ),
此功能可以更改所有文本。
答案 4 :(得分:-1)
你为什么要改变它们?如果要更改语言,请使用语言包(也可能用于更改英语文本)
答案 5 :(得分:-1)
我希望更好的方法来解决你的问题。只需复制并粘贴您的functions.php主题即可。好
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;
}
add_filter('woocommerce_catalog_orderby','wc_customize_product_sorting');