最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - Wooocommerce disable check_cart_item_stock if cart item has specific meta

programmeradmin0浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

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

发布评论

评论列表(0)

  1. 暂无评论