BASit Bulbulia
Forum Replies Created
Viewing 4 replies - 1 through 4 (of 4 total)
-
Forum: Plugins
In reply to: [WooCommerce] Stock of parent sku must be equal to stock of all variations.I tested this code and it works . . .
Code goes to functions.php of your theme or child theme.
add_action( 'woocommerce_reduce_order_stock', 'lets_reduce_parent' ); function lets_reduce_parent( $order_id ) { $order = wc_get_order( $order_id ); foreach( $order->get_items() as $item_id => $item ){ $parent_id = $item->get_product_id(); $child_id = $item->get_variation_id(); $quantity = $item->get_quantity(); if($child_id == 0) return; else { $parent_product = wc_get_product( $parent_id ); $stock = $parent_product->get_stock_quantity(); $new_stock = $stock - $quantity; wc_update_product_stock( $parent_product, $quantity, 'decrease' ); $order->add_order_note( "Parent Product ID: $parent_id - Stock Reduced: $stock -> $new_stock"); } } }
- This reply was modified 5 years, 4 months ago by BASit Bulbulia.
Forum: Plugins
In reply to: [WooCommerce] Stock of parent sku must be equal to stock of all variations.The solution I require is that the ghost product as you call it (Parent item) stock must also change.
Forum: Plugins
In reply to: [WooCommerce] Stock of parent sku must be equal to stock of all variations.Thanks Mike ! I tried what you suggested and it does not work. The variants do change stock but the parent stock remain the same . . .
- This reply was modified 5 years, 4 months ago by BASit Bulbulia.
Viewing 4 replies - 1 through 4 (of 4 total)