Home Forums Plugins Store Exporter Deluxe [Resolved] Quantity for Variable Products Reply To: [Resolved] Quantity for Variable Products

#41181
Lena
Participant

Update:

So even if you set Filter Products by Product Type Variation you get the quantity of every variation but the parent is still 0 but shoud be the sum of all variations in my understanding.

I had to do some minor alterations, maybe you can consider them in the next update:
#includes/product.php
# line 1781 – add a wc product
function woo_ce_get_product_data( $product_id = 0, $args = array(), $fields = array() ) {
$_pf = new WC_Product_Factory();
$wc_product = $_pf->get_product($product_id);

# ~line 1813 – get the variation prices if it is no single
if( $wc_product->is_type( ‘variable’ ) ){
if ($wc_product->get_variation_regular_price(‘min’, false) == $wc_product->get_variation_regular_price(‘max’, false){
$product->price = $wc_product->get_variation_regular_price(‘min’, true);
$product->sale_price = $wc_product->get_variation_sale_price(‘min’, true);
} else {
$product->price = $wc_product->get_variation_regular_price(‘min’, true).” – “.$wc_product->get_variation_regular_price(‘max’, true);
$product->sale_price = $wc_product->get_variation_sale_price(‘min’, true).” – “.$wc_product->get_variation_sale_price(‘max’, true);
}
} else {
$product->price = get_post_meta( $product_id, ‘_regular_price’, true );
$product->sale_price = get_post_meta( $product_id, ‘_sale_price’, true );
}

# ~line – get_total_stock works with single and variations
# $product->quantity = ( function_exists( ‘wc_stock_amount’ ) ? wc_stock_amount( $product->quantity ) : $product->quantity );
$product->quantity = $wc_product->get_total_stock();

####
With this changes all Prices and Sale Prices and Quantity where shown correct, as single as it was before and as variable product the parent shows the sum of all Variation quantities and the price is also taken from the variations, min – max if the variations have different prices.

Feel free to use any of this as you with.

karim.shehata@terravity.com

– working for Lena ..