24regular price

Solutions on MaxInterview for 24regular price by the best coders in the world

showing results for - " 24regular price"
Simona
31 Apr 2016
1global $post, $product;
2
3if ($product->is_on_sale()) :
4
5
6	// Dans le cas où le produit est "variable" (plusieurs variations de produits existantes)
7	if ($product->get_type() == 'variable') :
8
9		$available_variations = $product->get_available_variations();
10		$max_percentage = 0;
11
12		// On passe au crible toutes les variations et calcule le pourcentage de réduction de chacune.
13		// Si ce pourcentage de réduction est le maximum, on le garde en mémoire dans $max_percentage
14		for ($i = 0; $i < count($available_variations); ++$i) {
15			$variation_id = $available_variations[$i]['variation_id'];
16			$variable_product1 = new WC_Product_Variation($variation_id);
17			$regular_price = $variable_product1->get_regular_price();
18			$sales_price = $variable_product1->get_sale_price();
19			$percentage = round(((($regular_price - $sales_price) / $regular_price) * 100), 1);
20
21			if ($percentage > $max_percentage) {
22				$max_percentage = $percentage;
23			}
24		}
25		echo apply_filters( 'woocommerce_sale_flash', '<span class="onsale">-' . round($max_percentage) . '%</span>', $post, $product );
26
27
28	// Si le produit n'est pas "variable" mais simple, nous n'avons qu'un prix normal et un prix promo... fastoche !
29	elseif ($product->get_type() == 'simple') :
30
31		$percentage = round( ( ( $product->get_regular_price() - $product->get_sale_price() ) / $product->get_regular_price() ) * 100 );
32		echo apply_filters( 'woocommerce_sale_flash', '<span class="onsale">-' . round($percentage) . '%</span>', $post, $product );
33
34	endif;
35
36endif; 	
queries leading to this page
24regular price 24regular price