php - How does WooCommerce ensure that a product doesn't run out of stock during payment?

Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

I'm gonna make my own "reduce stock" functionality in WooCommerce. But first I'm trying to find out which hooks to use and how WooCommerce currently is reducing stock on the "creating order procedure".

I read this Stack Overflow post where it's recommended to add the custom stock decreasing functionality in the woocommerce_payment_complete hook.

And that hook is called after the payment procedure. Which makes me think;

What if someone else buys the last one and is quicker with the payment? Then my payment will complete, and then not reduce the stock. But two products needs to be sent. That's a problem.

Wouldn't it be better is the stock was reduced just before payment and then if payment fails decrease stock again? Why isn't it like that?

Or have I missed something? How does it work? I know there is a "hold stock" functionality too. But I don't really get how that works. I have looked in the check_cart_item_stock() function in class-wc-cart.php and I don't really understand what's happening there. My guess also is that WC's "hold stock" only is for when an order is already created but not paid. Is that right? So it doesn't hold stock when you have a product in cart?

Can someone tell me how WooCommerce ensures that a product doesn't run out of stock during payment?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745239760a4618110.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信