How i can get variable product sale price percentages in separate
-
Hi,
I wanted to do the following
Get the variable product sale price percentage in separate per variation. I tried the following
$available_variations = $product->get_available_variations(); $maximumper = 0; for ($i = 0; $i < count($available_variations); ++$i) { $variation_id=$available_variations[$i]['variation_id']; $variable_product1= new WC_Product_Variation( $variation_id ); $regular_price = $variable_product1 ->regular_price; $sales_price = $variable_product1 ->sale_price; $percentage= round((( ( $regular_price - $sales_price ) / $regular_price ) * 100),1) ; echo $price . sprintf( __('%s', 'woocommerce' ), $percentage . '<span class="main_sale_percentage_sign">%</span></p>'); }
But by this code am getting all variations percentages. How i can get them in separate so i can display one per click on variation change?
Thanks in advance.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘How i can get variable product sale price percentages in separate’ is closed to new replies.