WooCommerce, 實用技巧

翻譯 WooCommerce 移除購物車商品跳出英文提示

翻譯 WooCommerce 移除購物車商品跳出英文提示

這個有點奇怪,原本以為 WooCommerce 中文語系應該都有翻譯的,卻沒有在其翻譯檔案裡找到這個字串,只好透過一些語法來達到此方式。

翻譯 WooCommerce 移除購物車商品跳出英文提示
這個是原本跳出來的 POPUP 視窗提示,上頭寫著「Are you sure you want to remove this item from cart?」

我們今天要透過 Code Snippets 去翻譯,避免動到 WC 的程式,不然每次更新又要被蓋掉了,很簡單,在這裡面我們加上以下語法:

// 翻譯購物車提示
function uni_transfer_wccart_text ( $text ) {
         if ($text == 'Are you sure you want to remove this item from cart?'){$text = '你要將此商品從購物車移除嗎?';}
                return $text;
         }
add_filter( 'gettext', 'uni_transfer_wccart_text' );

接著啟動它,就可以完成翻譯囉

翻譯 WooCommerce 移除購物車商品跳出英文提示
是不是很簡單呢?

相關文章