2014-12-02 121 views
2

我在網上找到了一個解決方案,但它似乎不起作用。woocommerce更改相關產品文本

它說編輯我前幾天做的下面的文件,但不知何故它仍然不工作。

/wp-content/plugins/woocommerce/templates/single-product/related.php

哪,如果我的FTP服務器的文件顯示如下:

if ($products->have_posts()) : ?> 

<div class="related products"> 

    <h2><?php _e('You may also like', 'woocommerce'); ?></h2> 

但是該網頁仍然顯示'相關產品',而不是'您可能也喜歡'

由於某種原因,這並未發生或正在被某處過度。

任何想法?

回答

7

覆蓋默認模板的最佳方法是將文件複製到當前主題中名爲/woocommerce/single-product的文件夾。對該文件進行更改。

一般覆蓋像

/wp-content/plugins/woocommerce/templates/<foldername>/<filename>

Woocommerce模板文件將文件複製到

/wp-content/<your-theme>/woocommerce/<foldername>/<filename>

+0

我懷疑這是答案。 @ user3710926你不應該直接編輯WooCommerce核心文件。 – helgatheviking 2014-12-02 23:20:10

+1

只是爲了澄清;那個特定的文件應該被複制到你的主題文件夾中作爲'woocommerce/single-product/related.php'。您維護在插件模板文件夾中找到的文件夾層次結構。 – Dre 2014-12-03 09:00:52

+0

編輯答案,謝謝@Dre – RST 2014-12-03 16:59:26

17

我發現這對孩子的functions.php:http://speakinginbytes.com/2013/10/gettext-filter-wordpress/

/** 
* Change text strings 
* 
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext 
*/ 
function my_text_strings($translated_text, $text, $domain) { 
    switch ($translated_text) { 
     case 'Related Products' : 
      $translated_text = __('Check out these related products', 'woocommerce'); 
      break; 
    } 
    return $translated_text; 
} 
add_filter('gettext', 'my_text_strings', 20, 3); 

很好這裏的工作原理:https://mo-sound.com/en/shop/ball-speaker-classic-white/

+4

這是正確的解決方案,功能覆蓋。主題文件也可能會更新,而不是主題更改。 – 2016-09-19 08:24:04

+0

這是正確的代碼。如果你的網站是多語言的,你需要用switch($ text)替換switch($ translated_text) – retroriff 2017-01-31 10:22:41

+0

謝謝你的重新申請!如果我想添加產品的名稱我該怎麼辦? – 2017-02-17 17:25:44

0

這裏是user5217948的代碼所需要的情況下更新從Frithir

// CHANGE RELATED PRODUCTS TEXT 
function my_text_strings($translated_text, $text, $domain) { 
    switch ($translated_text) { 
     case 'Related products' : 
      $translated_text = __('You may also like...', 'woocommerce'); 
      break; 
    } 
    return $translated_text; 
} 
add_filter('gettext', 'my_text_strings', 20, 3); 

該代碼可以使用WooCommerce 3.3.1和4.9.4的WordPress(大約兩2018年2月)。


相關問題