如何更改店面主题上的"添加到购物篮"文本



我似乎无法替换单个产品页面上"添加到购物篮"按钮内的文本,我使用了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;
}

最新更新