我可能会做的是创建一个扩展简单产品类的新产品类型。我根本不打算进入代码,但看起来我已经回答了几个可能对你有用的问题。这不是一个完整的复制粘贴解决方案,因为这是一个相当大的工作,但这应该让你开始。
creating a custom product type
虽然我可能会延长WC_Product_Simple
而不是WC_Product
因为基本上这将是一样简单的产品,要注意以下几点:
你加1元字段定义你的“批”的大小。
Define product meta fields for custom product type only
然后创建自己的记事本模板使用了“大量的”大小操纵加入量输入(最小和步骤)那种类型。
add_action('woocommerce_your_type_add_to_cart', array($this, 'add_to_cart_template'));
function custom_type_add_to_cart_template() {
global $product;
// Load the add to cart template
wc_get_template(
'single-product/add-to-cart/your-type.php',
array(), // you can pass global variables here, ex: your product's "lot" size would be a good idea
'',
YOUR_PLUGIN_PATH . '/templates/'
);
}
最后,将购物车中的总价调整为$price * $quantity/$lot_size
。
考虑到一切工作自然与数量在1和2我想在一个可能的jQuery方法,我只是操纵显示的值。虽然担心HTML5控件/事件的跨浏览器支持。 – RyanMac 2014-11-05 22:38:35
我对此很感兴趣,但是你能不能把数量保持为1,2,3等等,并注意你在卖什么盒子/ 200多盒? – helgatheviking 2014-11-06 12:58:20
不可否认,这是计划A,但我们有一个独特的产品,我们实际上出售名片书籍,因此1“订单”是8张“卡片”,总共是200张“卡片”。我宁愿尽我所能来消除尽可能多的混乱。 – RyanMac 2014-11-06 20:01:30