更改 WooCommerce 中的“添加到购物车"按钮文本以用于具有变体的项目 [英] Changing the Add To Cart button text in WooCommerce for items with variations

查看:11
本文介绍了更改 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 中的“添加到购物车"按钮文本以用于具有变体的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆