fahadmahmood8 / stock-locations-for-woocommerce

This plugin will help you manage WooCommerce Products stocks through locations and also different traditional barcodes.
https://pt.wordpress.org/plugins/stock-locations-for-woocommerce/
GNU General Public License v3.0
22 stars 14 forks source link

Backorder status not being updated correctly #121

Closed gferguson78 closed 2 years ago

gferguson78 commented 2 years ago

I've just noticed an issue where products which are available on backorder are being set to 'outofstock' when they sell out rather than being set to 'onbackorder'.

For instance - I have a product which is set to 'allow but notify' for backorders and I have 2 of these left in stock. When I purchase both of these items at checkout the expected behaviour is that the stock levels will be reduced to zero and the stock status will go to 'onbackorder'. The stock is being deducted correctly but the stock status is going straight to 'outofstock' rather than 'onbackorder' and this then prevents them from being sold online. The backorder status stays the same though at 'allow but notify'. I'm happy to show you this behaviour on our staging site if you need further clarification.

Thanks, Gordon

gferguson78 commented 2 years ago

I've made a small change in the helper-slw-product.php file on line 49 and this appears to have rectified the issue:

I changed it from:

if( ! $product->is_on_backorder() ) { to if (! $product->backorders_allowed() ){

This seems to make more sense as I don't think the product will have been put onto backorder by this point in the transaction as the backorder status is updated by the next part of the code (from line 64 - backorder enabled) - therefore checking to see if backorders are allowed for this product would seem to be a better way of working out what the stock status of the product should be getting set to.

I've tested this for products where backorders are allowed and not allowed and the stock status seemed to get updated correctly each time.

When you get a chance could you review this and see if this makes sense? I can again show you this behaviour on our staging site if you need further details.

Thanks, Gordon

fahadmahmood8 commented 2 years ago

Thank you, I am taking this chunk from here.