celestex
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Forum: Plugins
In reply to: [WooCommerce] When one variation purchased the other go out of stockI found solution if you add this code in functions.php you can set :
– If a variation of one product is out of stock then the all product variation go sold out.
<?php
add_filter('woocommerce_available_variation', 'set_all_variations_out_of_stock', 10, 3 ); function set_all_variations_out_of_stock( $data, $product, $variation ) { // Set the Id(s) of the related variable product(s) below in the array if( $product->get_id() ) { $out_of_stock = false; // initializing // Loop through children variations of the parent variable product foreach( $product->get_visible_children() as $_variation_id ) { if( $_variation_id != $data['variation_id'] ) { $_variation = wc_get_product($_variation_id); if( ! $_variation->is_in_stock() ) { $out_of_stock = true; // Flag as out of stock break; } } } if ( $out_of_stock ) { $data['availability_html'] = '<p class="stock out-of-stock">'. __('Out of stock', 'woocommerce') .'</p>'; $data['is_in_stock'] = false; } } return $data; }?>
Forum: Plugins
In reply to: [WooCommerce] When one variation purchased the other go out of stockHello, is the plugin include unlimited Inventory reduction per item sold ?
Viewing 2 replies - 1 through 2 (of 2 total)