fahadmahmood8/stock-locations-for-woocommerce

Stock locations not being updated on order when status is changed

Closed this issue · 27 comments

Hi there,

I've noticed an issue on our site that happens whenever I manually change the status of an order - the stock locations are not automatically updated. I'll try and explain the issue - this has only been tested with auto-allocate enabled as that is what we use.

If an order is already in status 'processing' and stock has been automatically allocated - when I then change the status to 'pending' then stock allocations are automatically removed. This works correctly - exactly as it should.

If I then change the status back to 'processing' without making any changes to the allocations I get a message saying 'Stock in locations updated successfully!' - however the locations are not updated. The fields to allow me to manually update the allocations are still visible and when I move to another page I then get the message saying 'Partial or total stock in locations is missing in this order. Please fill the remaining stock.'

I would expect that whenever I change the status of the order from 'pending' or 'on-hold' or 'cancelled' back to 'processing' that the location data should be auto-allocated again - is this not correct?

We also use the Klarna payment plugin on our site and I've noticed that when a Klarna payment fails or is declined the order that is created sits on the backend as 'pending payment' - however the stock still sits as having been allocated. This is more of less the reverse of the issue I've listed above! I would assume that when the status goes to pending-payment then the stock allocation should be removed from the order in the same was as it does when I change the status manually. This means that when a Klarna order fails the items on the order can no longer be purchased until I manually go in to change the pending order and remove the stock allocation.

I can provide access to our dev site for testing these issues if required.

Many thanks,
Gordon

Thanks Fahad,

That's great to hear. If I can help at all please let me know. I've already setup a fairly basic 'smart' order allocation system for the plugin that checks stock availability over both our branches and it can then allocate stock to a single branch if they have everything in the order in stock.

Gordon

Just a quick update on the issue I'm having with stock being allocated to orders which are pending payment. It seems that stock is being allocated to orders too early in the sales process. Stock is allocated and reduced using the 'woocommerce_new_order_item' hook which is triggered whenever an order is created. I believe the default behaviour for WooCommerce orders is that stock is allocated and deducted whenever an order has moved to either on-hold or processing status. I've tried disabling the SLW plugin and that does seem to be the way that it works normally.

The main issue with stock being allocated so early is that if the customers payment fails or if they cancel the payment process, the order has already been created and the stock has been allocated to it and will no longer be purchaseable by anyone else. Payment plugins like Klarna or other finance plugins have to create the order in WooCommerce with 'pending payment' status before the customer goes to complete the application process.

Is it possible to modify the behaviour of the plugin so that stock only gets allocated and deducted after the order status changes to on-hold or processing? This would solve the issue we are currently experiencing.

Many thanks,
Gordon

Hey, We are having this same exact problem. We need to manually re-stock the stocks after failed payment. That new update didn't help. It still doesnt automatically re-stock.

In the latest version, there is a help section and an urgent help option. We can schedule a screen sharing session through Google meeting to understand this issue better. Are you comfortable with this?

On Sun, Dec 12, 2021 at 2:33 PM JReeeee @.***> wrote: Hey, We are having this same exact problem. We need to manually re-stock the stocks after failed payment. That new update didn't help. It still doesnt automatically re-stock. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#117 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALLCP2LSVCDJ6J3K3ZRELLUQRT7FANCNFSM5JFWRAWA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
-- Thanks, Fahad

Hey, this sounds good. If we just could get this fixed otherwise the plugin is working like a charm.

Let's meet in 1 hour if thats good for you.

Alright, lets go

Im here, on the waiting room

Hey,

Since you didnt join. Shall we book good time thats suitable for you?

Here i am

Hi there,

I have tested this this morning but the issue is still the same. Stock is being deducted too early in the order process. It's being deducted as soon as the order is created, not when the order goes to status 'processing'. When I create a test order using Klarna or finance an order is created on the system as status 'pending payment'. Stock is being deducted by the plugin at this point when it shouldn't be. If the customer then abandons the checkout process for Klarna/finance then the order sits on our system as 'pending payment' and the stock remains deducted and can't be purchsed by anyone else. It won't go back into stock until we manually update the order status to cancelled or failed. We have no order hold time setup on our system.

You can find out more info about the Klarna order flow here: https://krokedil.com/new-flow-in-klarna-checkout-for-woocommerce/

The main issue we have is this:

If a customer is buying a one-off product from our site using Klarna or finance but their application gets rejected they can't then go back to try a different method of payment as the stock in their cart has now been allocated to their previous order attempt and is now out of stock and unable to be purchased.

I would recommend that the stock should only be deducted by the plugin when payment has been completed by the customer and the status of the order is moved to 'processing'. This would mean changing the 'newOrderItemAllocateStock' hook from 'woocommerce_new_order_item' to run instead at 'woocommerce_order_status_processing' - this is more in line with the way that WooCommerce allocates stock in general. It would however have to be hooked in before order emails are processed to be able to send out emails to each location stock location.

I have done some experimenting with this so feel free to contact me directly and I can explain how far I got with this. I also have an idea for smart order allocation - to allow the order to be allocated to a single location if they have all of the order items in stock.

Many thanks,
Gordon

I'd be more than happy to contact you via Google Meetings. Please let me know when would suit and we can arrange this.

The new changes for cancelled/pending & failed orders are very welcome but unfortunately they don't fix the issue I have with Klarna payments or when a customers payment fails. The order always stays in 'pending payment' and doesn't change status until I manually change it or delete the order so the stock allocation is never removed until it gets changed manually.

Many thanks,
Gordon

Hi. We are having this exact same issue.
I would be glad to join a meeting to discuss workarounds.
Cheers!

Perfect, lets connect in the next week. Let me know how would you like to connect?

@fahadmahmood8 I can meet on Tuesday or Thursday afternoon (11AM - 3 PM UTC).
Let me know when and I will set up the meeeting and send you the link and pass some minutes before.

Ok, you may schedule a meeting and we will connect.

@fahadmahmood8 sorry for not reaching back to you. I can still do 11AM - 3 PM UTC any day of this week if you are still available.

I am still available and you can ping me on slack directly or reach me through the mail address mentioned under the help tab on the settings page of the plugin.

@fahadmahmood8 I can meet to discuss this issue as it's still happening in our site.
I'll contact you via email to send you meeting link.
Also, could you please reopen this issue? So if someone is troubleshooting this problem, they can quickly see this is an active issue in the plugin?

Cheers!

No need to reopen this issue because this plugin is evolving with every single round of usage. I am available for support and continuously improving it. As it has multi directions and every test environment has different parameters so things are taking time to get a shape.