admin管理员组文章数量:1316693
I add birthlist functionnality to my woocommerce store. I would like to authorize the order of an out-of-stock product only if the product is purchased on the birthlist.
On my function to add a product to the shopping cart from the birthlist, I skip the stock availability check. The product is now added to the cart. I also add a meta to the item in the cart with the birthlist ID.
But I got an error on cart and checkout about stock.
How to deactivate the stock check of the shopping cart programmatically.
Actually woocommerce make this check on includes/class-wc-cart.php in check_cart_item_stock method
I add birthlist functionnality to my woocommerce store. I would like to authorize the order of an out-of-stock product only if the product is purchased on the birthlist.
On my function to add a product to the shopping cart from the birthlist, I skip the stock availability check. The product is now added to the cart. I also add a meta to the item in the cart with the birthlist ID.
But I got an error on cart and checkout about stock.
How to deactivate the stock check of the shopping cart programmatically.
Actually woocommerce make this check on includes/class-wc-cart.php in check_cart_item_stock method
Share Improve this question edited Nov 12, 2020 at 8:13 ZecKa asked Nov 12, 2020 at 7:00 ZecKaZecKa 7781 gold badge6 silver badges12 bronze badges1 Answer
Reset to default 1Finally, I did it like this:
function bo_disable_stock_check(){
if(bo_cart_contain_birthlist()){
remove_action('woocommerce_check_cart_items', [WC()->cart, 'check_cart_items'], 1);
add_filter("woocommerce_product_is_in_stock", "__return_true");
add_filter("woocommerce_cart_item_required_stock_is_not_enough", "__return_false");
}
}
add_action('wp','bo_disable_stock_check');
But maybe there are more specific hooks to call than "wp".
本文标签: woocommerce offtopicWooocommerce disable checkcartitemstock if cart item has specific meta
版权声明:本文标题:woocommerce offtopic - Wooocommerce disable check_cart_item_stock if cart item has specific meta 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741999653a2410749.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论