• Resolved freddyeee

    (@freddyeee)


    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)
  • Plugin Support Aamir

    (@aamiribsf)

    Hello @freddyeee ,

    Greetings for the day!

    I suggest conducting a test with the Default dropdown variations to verify the code’s functionality. If you haven’t already, consider temporarily disabling the Variation Swatches plugin and check if the code seamlessly works with the default WooCommerce variation display. This step will help determine if the issue is associated with the variation swatches.

    Anticipating your response.

    Best Regards,

    Plugin Support Aamir

    (@aamiribsf)

    Hello freddyeee ,

    It’s been a while since we haven’t heard from you so we are marking this thread as resolved.

    If you faced any other issues while using our product, feel free to start a new thread.

    Best regards,

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Code issue on product pages’ is closed to new replies.