ClassicPress / classic-commerce

A simple but powerful e-commerce platform built for ClassicPress. Forked from WooCommerce and compatible with many Woo extensions.
https://classiccommerce.cc/
GNU General Public License v3.0
50 stars 15 forks source link

wc_maybe_adjust_line_item_product_stock() #337

Closed magenta-cuda closed 2 years ago

magenta-cuda commented 2 years ago

WooCommerce now has a function wc_maybe_adjust_line_item_product_stock() defined in wc-admin-functions.php to adjust stock quantity when an order item is deleted. This function is called by wc_save_order_items() and WC_AJAX::remove_order_item(). You may want to add this function and its calls to ClassicCommerce.

N.B. The function wc_maybe_adjust_line_item_product_stock() use the data base field '_restock_refunded_items' of table $wpdb->prefix . 'woocommerce_order_items'. This data base field did not exists for order version less than 5.5. However, it can be created using the function WC_Order::get_qty_refunded_for_item(). (See RestockRefundedItemsAdjuster::initialize_restock_refunded_items())

N.B. I think when this featured was first introduced into WooCommerce it may have also introduced a bug. See issue https://github.com/woocommerce/woocommerce/issues/29502. I checked and this bug does not exists in ClassicCommerce 1.0.4. So, it was introduced sometime later, maybe by the introduction of this feature. So some care should be taken implementing this.

ghost commented 2 years ago

Thanks for this. Sounds like a useful addition.

wc_maybe_adjust_line_item_product_stock() WC 3.6.0
Sees if line item stock has already reduced stock, and whether those values need adjusting e.g. after changing item qty.

We are a little short on developers at the moment but will keep it in mind.