首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在WooCommerce中更改添加到购物车库存错误通知

在WooCommerce中更改添加到购物车库存错误通知
EN

Stack Overflow用户
提问于 2018-12-15 19:58:19
回答 3查看 1.7K关注 0票数 2

当客户试图向购物车中添加过多的商品时,他们会看到以下错误通知:

你不能把这个数量加到购物车里--我们有X的存货,你已经有Y在你的购物车里了。

此行为包含在方法源代码一零六七中。

我想隐藏库存细节,并将其替换为:

你不能把那笔钱加到购物车里--我们的存货不够。

如何在不覆盖源代码的情况下,在WooCommerce中更改此添加到购物车股票错误通知?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-12-15 21:58:30

您可以在的帮助下更改上述文本,而无需修改插件文件“说明什么”插件。按照以下步骤更改文本:

  1. 安装说什么插件
  2. 访问Tools > Text Changes
  3. 单击添加新
  4. 根据你的需要填写这些字段。
代码语言:javascript
复制
- **Original string:** `You cannot add that amount to the cart — we have %1$s in stock and you already have %2$s in your cart.`
- **Text domain:** `woocommerce`
- **Text context:** 
- **Replacement string:** `You cannot add that amount to the cart — we don't have enough in stock.`

  1. 单击“添加”按钮以保存更改。
票数 1
EN

Stack Overflow用户

发布于 2018-12-16 04:42:06

这可以在自定义钩子函数中使用gettext筛选器钩子,方法如下:

代码语言:javascript
复制
add_filter( 'gettext', 'custom_add_to_cart_stock_error_notice', 10, 3 );
function custom_add_to_cart_stock_error_notice( $translated, $text, $domain ) {

    if ( $text === 'You cannot add that amount to the cart — we have %1$s in stock and you already have %2$s in your cart.' && 'woocommerce' === $domain ) {
        $translated = __("You cannot add that amount to the cart — we don't have enough in stock.", $domain );
    }

    return $translated;
}

代码在您的活动子主题(或活动主题)的function.php文件中。测试和工作。

票数 2
EN

Stack Overflow用户

发布于 2021-06-27 16:53:50

请注意,@loictheaztec的代码工作正常,但如果要使用数量,则需要在第四行中将引号更改为单引号。

代码语言:javascript
复制
    add_filter( 'gettext', 'custom_add_to_cart_stock_error_notice', 10, 3 );
function custom_add_to_cart_stock_error_notice( $translated, $text, $domain ) {

    if ( $text === 'You cannot add that amount to the cart — we have %1$s in stock and you already have %2$s in your cart.' && 'woocommerce' === $domain ) {
        $translated = __('You cannot add that to the cart — we have %1$s in stock and you already have %2$s in your cart.', $domain );
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53796760

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档