在 WooCommerce 中使 +/- 加号和减号按钮以 12 为增量增加 [英] Making the +/- Plus and Minus quantity button go up in increments of 12 in WooCommerce

查看:35
本文介绍了在 WooCommerce 中使 +/- 加号和减号按钮以 12 为增量增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试解决我认为可能很容易解决的问题,但我似乎在任何地方都找不到任何信息.

I have been trying to solve what I thought might be an easy fix but I can't seem to find any information anywhere.

我的问题是:

我正在使用 WooCommerce 和最小/最大数量和批发商店插件建立批发商店.我想展示一个单价的简单产品(没问题),但由于商店中的所有产品都是批发的,因此它们只能以 6 或 12 个(多个)纸箱的形式出售.

I am setting up a wholesale store using WooCommerce with the min/max quantity and wholesale store plugins. I want to show a simple product with its single unit price (no problem) but as all products in the store are wholesale they can only be sold in (multiples) cartons of 6 or 12.

最小/最大插件允许我设置最小订单数量(比如 12 件),但是当我点击 -/+ 减号和加号数量选择器添加另一个纸箱(另外 12 件)时,它只会添加一个数字(单个项目)一次......例如13、14、15、16 等等.

The min/max plugin allows me to set a minimum order quantity (say 12 items) but when I click on the -/+ Minus and Plus quantity selector to add another carton (another 12 items) it only adds one number (single item) at a time... E.g. 13, 14, 15, 16 and so on.

所以我的问题是...是否可以修改 'quantity.php' 文件,以便订单数量仅以 12 为增量增加?"(例如 12、24、36、48 等)

So my question is... "Is it possible to modify the 'quantity.php' file so the order quantities only go up in increments of 12?" (E.g. 12, 24, 36, 48, etc.)

我知道我可以简单地设置并显示单个纸箱成本作为一个简单的产品或做变量,但我的客户想要显示每单位价格.

I know I could simply set up and show the single carton cost as a simple product or do variables but my client wants to show a per unit price.

提前感谢您的任何反馈.

Thanks in advance for any feedback you may have.

推荐答案

无需更改核心,甚至无需使用 WooCommerce 的模板覆盖.正如 Rashid 指出的那样,有一个过滤器可以修改这个值.我们只需要使用它.将其放入站点特定插件.

There's no need to change core, nor even to use WooCommerce's template override. As Rashid points out, there is a filter in place for modifying this value. We just need to use it. Put this in a site-specific plugin.

add_filter( 'woocommerce_quantity_input_step', 'kia_quantity_input_step', 10, 2 );
function kia_quantity_input_step( $step, $product ){
    return 6; // the will be the new step value
}

这篇关于在 WooCommerce 中使 +/- 加号和减号按钮以 12 为增量增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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