2016-05-25 100 views
0

如何更改,在上一個版本Woocommerce,這個文本 - enter image description here如何更改Woocommerce「排序」文本?

+1

你嘗試過什麼嗎?爲什麼不搜索代碼中的文本以查看它來自哪裏? – bodangly

+0

是的,我試過了,但是沒有任何東西......顯然我對代碼不是很熟悉。( – Jasper

+1

描述你的嘗試可以幫助我們避免時間告訴你去做已經完成的事情。 – helgatheviking

回答

0

爲什麼你想要改變它們?如果你想改變語言,然後使用語言包(這可能會改變英文文本)

+0

因爲在其他語言中woocommerce通常沒有完全翻譯,在我的情況下,部分描述,菜單,答案沒有翻譯,所以我翻譯我自己! – Jasper

+0

因此,你已經下載一個翻譯包?那麼爲什麼不直接翻譯.po文件中的那些未翻譯的部分,並將其創建爲新的.mo文件。 – Dope

+0

由於選項說的不是默認值,我猜你的主題已經修改了值,可能沒有完整的語言包WooCommerce核心被翻譯成很多種語言 – helgatheviking

2

添加到您的主題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

這裏是你如何可以通過woocommerce_catalog_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有「默認排序」而不是「按默認排序」。 「按名稱排序」也不是核心的一部分。

0

對於男生,誰是尋找它在溶液中二〇一七年至2018年(版本4.9.1)...

的wp-content>插件> woocommerce>包括> WC-模板的functions.php

搜索:「function 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'), 

所有的文字都可以在這個功能中改變。

+1

覆蓋_core files_從來不是一個好習慣,與更新一樣,它們也會更新。 – dferenc

1

我希望能更好的解決您的問題。只需複製並粘貼您的主題的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; 
} 
0

我希望更好的方法來解決你的問題。只需複製並粘貼您的主題的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');

+1

請將此答案作爲副本刪除。 – Sam