简体   繁体   English

WooCommerce中的库存数量例外

[英]Making an exception to stock quantity in WooCommerce

Right now, I am bringing users to a Contact 7 Form, and adding to cart using the href link, http://example.com/checkout/?add-to-cart=1000 现在,我将用户带到Contact 7表单,并使用href链接http://example.com/checkout/?add-to-cart=1000添加到购物车

I have a unique case where if there is 1 item left of product 1000, and the user chooses 2 in the dropdown box, then I should increase product 1000's quantity by 2 and allow the user to checkout normal. 我有一个独特的情况,如果产品1000剩余1件,并且用户在下拉框中选择2,那么我应该将产品1000的数量增加2,并允许用户正常签出。

I have looked at the woocommerce_add_to_cart and woocommerce_add_to_cart_validation hooks, but couldn't figure it out. 我已经看过woocommerce_add_to_cartwoocommerce_add_to_cart_validation挂钩,但无法弄清楚。

I just need to understand, how I can make the modification before the user is directed to the checkout page and are not shown the "You cannot add that amount to the cart" message. 我只需要了解,在将用户定向到结帐页面并且没有显示“您无法将金额添加到购物车”消息之前,如何进行修改。

add_filter( 'woocommerce_product_get_stock_quantity', 'hook_get_stock_quantity', 10, 2 );
add_filter( 'woocommerce_product_variation_get_stock_quantity', 'hook_get_stock_quantity', 10, 2 );
function hook_get_stock_quantity( $value, $product ) {
    if($value < 2) $value = 10;
    return $value;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM