jamesgol / woocommerce-cart-stock-reducer

Allow WooCommerce inventory stock to be reduced when adding items to cart
GNU General Public License v2.0
58 stars 19 forks source link

Product available and stil not possible to checkout #95

Open codeagencybe opened 2 years ago

codeagencybe commented 2 years ago

Hello

Since one of the latest WooCommerce updates, we notice some serious issue with the stability of the plugin. Sometimes when a product is in stock, not reserved yet, customers can still not checkout.

SCreenshots of the problem:

Step 1 product is in stock, not in a cart yet

image

step 2 product is available to purchase I click add to cart

image

step 3 message shows correctly that its not longer available, I just added to cart

image

step 4 in backend, the info is also changed and correct qty in cart now says 1, which is correct

image

step 5 I want to check out so I go to cart or checkout directly But now I get an error that says Sorry, we do not have enough "X" in stock to fulfill your order (0 available). We apologize for any inconvenience caused. which is impossible, because there was 1 available and I just put it in my cart.

image

checkout also gives an error but without any clear indication what or how. So if clients go straight to checkout, they get confused not knowing what's going on.

image

We already tried all base checks:

I have no clue where it pulls that idea that there is no stock when I just put it in my cart like 2 seconds earlier. I also checked and compare the product meta fields data to see if I can find anything obscure or different but I can't find anything clear pointing to something.

Is this a known bug with WooCommerce from v6.x something? Anything else I need to check? Any other options how to force reset that availability?

Thanks!

jamesgol commented 2 years ago

I'll have to do some testing to see. Do you know which WooCommerce version it started in? It's such a moving target I don't always stay current.

What other WooCommerce related plugins do you have? I suspect if this was a problem everyone is having I'd have heard more about it.

codeagencybe commented 2 years ago

We are running WooCommerce 6.1.1 I can't remember when it started exactly, but I think it is from 6.x

Addiitional plugins list I already tried with disabling most of these to see if there is a conflict, but honestly most of these plugins are mostly related to orders itself like payment gateway, shipping, EU VAT, change email templates etc..., nothing that changes or manipulates stock or quantities. It also doesn't make any sense why any of these plugins would say a product is out of stock when there actually is stock.

Custom Order Numbers for WooCommerce Kadence WooCommerce Email Designer MailerLite - WooCommerce integration Mollie Payments for WooCommerce Sendcloud | Smart Shipping Service WooCommerce Cart Stock Reducer WooCommerce EU VAT Assistant WooCommerce Extended Coupon Features FREE WooCommerce PDF Invoices & Packing Slips WooCommerce PDF Invoices & Packing Slips Premium Templates YITH WooCommerce Badge Management Premium YITH WooCommerce Delivery Date Premium

I know some combinations sometimes can make an edge case but this project has been running good for almost 2 years now without issues. This just recently started giving problems and in such a way its unclear where the offset is from stock when it clearly is not.

jamesgol commented 2 years ago

I know there was some mention of a Gutenberg block for cart/checkout, any chance you are using that? I know when I briefly looked there were some significant changes.

codeagencybe commented 2 years ago

No we are not using anything from Gutenberg or any side related Gutenberg products. We do use Elementor pro with Astrawp theme, but also nothing used anywhere in WooCommerce related pages. So the cart, custom, my account, are all the "original" blank pages with nothing but the original WooCommerce shortcodes.

Elementor is only used for the regular websites parts (header, footer and some USP section on the product page) and the normal content pages like home, about us etc...

codeagencybe commented 2 years ago

Does your plugin creates a secondary stock value or something and inherites back to the original field or anything like that? I'm trying to find a way to troubleshoot and monitor this because I already figured out that the problem is not a global product problem. It does not happen for every product, only with specific products. Now the hard part is, there are 3500+ products and we have no idea which products are "bad". We receive random complaints about customers not being able to checkout. So we test ourselves and to our surprise everything works fine. Until we just "hit" one of those bad products that customers also try to checkout and then we can replicate the same problem as the end customers.

I already tried comparing meta field values to see if something is noticable but can't see anything that stands out. So this also confirms that it has to be something product-specific that is different or a problem with a stock value while that is very weird as in both backend and frontend, the product is just available to purchase. I can add to cart, but in the cart it says there is no stock and that causes problems further down to checkout.

Any other ideas we can try?

codeagencybe commented 2 years ago

Here's a recording of a "mixed" cart

https://share.codeagency.be/s/DjimZPxozMsfMJi

codeagencybe commented 2 years ago

debug.log is also completely 100% clean, no PHP errors at all. So this also confirms its not coming from a programmatic error but rather a database value / query that returns a wrong value at the cart/checkout level but correct on the product page.

jamesgol commented 2 years ago

Does your plugin creates a secondary stock value or something and inherites back to the original field or anything like that?

It just counts what's in the users carts and doesn't modify the database in any way.

Does it happen consistently to the exact same products?

Logged in users vs not logged in users?

codeagencybe commented 2 years ago

No I can't pinpoint exactly which products. So far it seems to be completely random. When it says unavailable, it also remains unavailable for that product. Even when they timer hits 0 and resets and dumps the cart, another person can add to cart but also get the same error. So there is something persistent happening on a random selection of products.

It does not make any difference logged in or not-logged in. Or customer vs admin vs shop admin user role. Everyone gets the same error on the same product.

jamesgol commented 2 years ago

You said you compared meta data and didn't see anything, can you dump those records and post them as well as a regular item that is working normal.

There was a "held stock" feature added to WooCommerce at some point, do you have that enabled? If you're digging in the database I believe they are tracking those in a separate table.

jamesgol commented 2 years ago

Did you get this figured out?

codeagencybe commented 2 years ago

@jamesgol

No unfortunately not, There is no logic sense happening at the moment. I also tried putting the "problem" product back in draft, change the stock qty to higher, reduce it back lower, change the stock status, ... basically anything that would trigger an update to the availibility in WooCommerce, but it keeps nagging about impossible to fulfil the quantity and show 0 available.

The only way we got it solved is by duplicating the product so it gets a new post ID and delete the problem product. But this is impossible to process like because there are 3000+ SKU's and we don't know which ones have this problem and which not. And this is only a temp workaround, because the problem will come back too if we don't know what's causing this.

I only have 1 certainty, which is we know it comes from your plugin, because when I disable it, there is no more error about availability. I'm still clueless what is causing the problem. Maybe its an edge case based on some combination wiht the other plugins or due to WooCommerce 6.x.x versions mentioned earlier but it doesn't add up why it still allows a client to add to cart but not to finish that same cart.

jamesgol commented 2 years ago

Did you dump the meta records and check on the "held stock" feature? Based on the error message and the code around it, the "held stock" quantity is used in a calculation that would make that message show up.

jamesgol commented 2 years ago

I've been trying to reproduce this issue and I have not had any luck. Did you check if you have the 'hold stock' feature enabled?

If you can send me a database dump that contains products that exhibit this issue I can try to duplicate it locally and attach a debugger to figure out the problem.

tdobson commented 2 years ago

I replicated this today. The item sold 15/20. Was shown as "sold out" on the page, but showed one in stock on the product page. When I clicked "update" on the product page - the items were available.

I probably can share more information here. I don't and have never used a hold stock feature.

jamesgol commented 2 years ago

@tdobson Please share any more information if you have it.

paco3346 commented 1 year ago

I had this same issue with PayPal Payments

The issue stemmed from the fact that this plugin (cart-stock-reducer) uses the following to skip checks during checkout/payment steps:

https://github.com/jamesgol/woocommerce-cart-stock-reducer/blob/c1a87b41e6ced080ce7fe0612e164841d061544f/includes/class-woocommerce-cart-stock-reducer.php#L1064

https://github.com/jamesgol/woocommerce-cart-stock-reducer/blob/c1a87b41e6ced080ce7fe0612e164841d061544f/includes/class-woocommerce-cart-stock-reducer.php#L1103

The PayPal plugin creates the order via an xhr call (wc_ajax=ppc-create-order) so I ended up adding that to the check as well.

if ( is_cart() || is_checkout() || ($_REQUEST['wc-ajax'] ?? '' === 'ppc-create-order')) {

Obviously my solution isn't portable but I suspect the same issue is causing the previous commenter's problems.