簡體   English   中英

如何更改店面主題上的添加到購物籃文本

[英]How to change Add to basket text on the storefront theme

我似乎無法替換單個產品頁面上添加到購物籃按鈕中的文本,我使用的是 WooCommerce 的店面主題的子主題。

這是我嘗試過的:

add_filter('woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_add_to_cart_text');

function woocommerce_custom_add_to_cart_text() {
   return __('Add to cart', 'woocommerce');
} 

按鈕在 DOM 上的顯示方式:

<button type="submit" name="add-to-cart" value="117" class="single_add_to_cart_button button alt">Add to basket</button>

我確實認為這個問題與主題有關,因為當我在測試站點上嘗試時,您的代碼確實有效,盡管我沒有將 Storefront 設置為主題。

您可以嘗試字符串替換:

add_filter( 'gettext', 'change_woocommerce_strings', 999, 3 );

function change_woocommerce_strings( $changed, $text, $domain ) {
$changed = str_ireplace( 'Add to basket', 'Add to cart', $changed );

return $changed;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM