本文介绍了在WooCommerce中更改添加到购物车按钮的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在运行WooCommerce版本2.5.5.以下代码行似乎并未更改具有变体的商品在我的产品页面上的添加到购物车"按钮上的文字:
I'm running WooCommerce version 2.5.5. The following lines of code don't seem to change the Add To Cart button text on my product page for an item with variations:
add_filter('variable_add_to_cart_text', 'my_custom_cart_button_text');
function my_custom_cart_button_text() {
return __('Buy Now', 'woocommerce');
}
您会碰巧知道我在想什么吗?
Would you happen to know what I'm missing?
推荐答案
单个产品页面的正确过滤器是 woocommerce_product_single_add_to_cart_text
.
The correct filter for the single product page is woocommerce_product_single_add_to_cart_text
.
function my_custom_cart_button_text( $text, $product ) {
if( $product->is_type( 'variable' ) ){
$text = __('Buy Now', 'woocommerce');
}
return $text;
}
add_filter( 'woocommerce_product_single_add_to_cart_text', 'my_custom_cart_button_text', 10, 2 );
这篇关于在WooCommerce中更改添加到购物车按钮的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!