Php 更改Woocommerce中特定产品的“添加到购物车”按钮文本

Php 更改Woocommerce中特定产品的“添加到购物车”按钮文本,php,wordpress,button,woocommerce,product,Php,Wordpress,Button,Woocommerce,Product,在woocommerce中,我能够使用以下代码将所有“添加到购物车”按钮文本更改为“+”: add_filter('woocommerce_product_add_to_cart_text', 'wh_archive_custom_cart_button_text'); // 2.1 + function wh_archive_custom_cart_button_text() { return __('+', 'woocommerce'); } 但现在我想将特定产品的按钮文本

在woocommerce中,我能够使用以下代码将所有“添加到购物车”按钮文本更改为“+”:

add_filter('woocommerce_product_add_to_cart_text', 
'wh_archive_custom_cart_button_text');   // 2.1 +

function wh_archive_custom_cart_button_text()
{
    return __('+', 'woocommerce');
}
但现在我想将特定产品的按钮文本更改为(小写)“添加到购物车”


非常感谢您的帮助。

以下代码将根据定义的产品ID更改“添加到购物车”按钮文本:

add_filter( 'woocommerce_product_add_to_cart_text', 'custom_loop_add_to_cart_button', 20, 2 ); 
function custom_loop_add_to_cart_button( $button_text, $product ) {
    // HERE define your specific product IDs in this array
    $specific_ids = array(37, 40, 53);

    if( in_array($product->get_id(), $specific_ids) ) {
        $button_text = __("add to cart", "woocommerce");
    } else {
        $button_text = __('+', 'woocommerce');
    }
    return $button_text;
}

代码进入活动子主题(或活动主题)的function.php文件。已测试且有效。

如果您想更改特定产品的“添加到购物车”按钮文本而不进行编码,以下是解决方案

  • .postid-1324=>产品id
  • .single_add_to_cart_button=>add to cart button类
  • .postid-1324.单个添加到购物车按钮:之后{
    内容:'';
    背景:rgb(106191119);
    宽度:110px;
    高度:45px;
    位置:绝对位置;
    左:0;
    右:0;
    文本对齐:居中;
    保证金:0自动;
    }
    .postid-1324.单个添加到购物车按钮:之前{
    内容:“将钱添加到钱包”;
    位置:绝对位置;
    z指数:999998;
    左:0;
    右:0;
    }