【问题标题】:Change ADD TO CART button text on the product price on the Store page [duplicate]在商店页面上更改产品价格上的添加到购物车按钮文本[重复]
【发布时间】:2017-04-20 10:33:07
【问题描述】:

在 WooCommerce 中,我们可以更改商店页面上产品价格附近的“添加到购物车”按钮文本吗?

我附上了图片:

【问题讨论】:

标签: php wordpress woocommerce product hook-woocommerce


【解决方案1】:

您可以使用过滤器轻松完成。请试试这个。

add_filter( 'woocommerce_product_add_to_cart_text', 'my_custom_cart_button_text', 10 );
function my_custom_cart_button_text() {

global $product;
    if (@$product->product_type == 'simple') {
        return __(get_woocommerce_currency_symbol().@$product->price, 'woocommerce');
    } else {
        // If needed the default behavior for all other products:
        // return __('My default text', 'woocommerce');
    }
}

【讨论】:

  • 把代码放到functions.php文件中?
  • @SavanDholu 我已经编辑了我的函数。是的,把它放在functions.php中
  • 我已经对其进行了测试并且可以正常工作。正如您提到的,您只想更改商店页面(/shop)上的文字,对吗?
  • 是的工作,但我有显示简单和可变的产品价格@Davinder Kumar
  • 如果它正在工作,请接受作为答案。您将需要创建一个函数并使用 ajax 调用可变产品以更改变化。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-20
  • 1970-01-01
  • 1970-01-01
  • 2018-05-12
  • 2018-03-05
  • 2021-07-21
相关资源
最近更新 更多