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".