Code issue on product pages
-
Hi
I used this code on the functions.php to show “You save(x%)” message under the price in every product page, but in some product pages with just 1 option color doesn’t work like this one: https://www.runayaq.com/producto/runayaq-mujer-polo-negritos-de-huanuco/ and in other products with 2 options of color, it appears like this :
Code used:
add_action( 'woocommerce_single_product_summary', 'display_savings_percentage', 12 ); function display_savings_percentage() { global $product; $regular_price = $product->get_regular_price(); $sale_price = $product->get_sale_price(); if ( ! $regular_price || ! $sale_price ) { return; } if ( $product->is_type( 'variable' ) ) { $min_price = $product->get_variation_regular_price( 'min', true ); $max_price = $product->get_variation_regular_price( 'max', true ); $min_sale_price = $product->get_variation_sale_price( 'min', true ); $max_sale_price = $product->get_variation_sale_price( 'max', true ); if ( ! $min_price || ! $max_price || ! $min_sale_price || ! $max_sale_price ) { return; } $regular_price = ( $min_price === $max_price ) ? $min_price : $min_price . ' - ' . $max_price; $sale_price = ( $min_sale_price === $max_sale_price ) ? $min_sale_price : $min_sale_price . ' - ' . $max_sale_price; } $savings_percentage = round( ( $regular_price - $sale_price ) / $regular_price * 100 ); echo '<p class="savings-percentage">You save ' . $savings_percentage . '%</p>'; }
how to fix that ?
The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Code issue on product pages’ is closed to new replies.