How to show original strikeout price and sales price even only one variation has discount

5 replies2 participantsUpdated by Luca Rossi

  • Avatar: kmc
    kmc
    Participant

    Now if a variation product has only one variable option has discount, it doesn’t show strikeout original price and new price, may I know how to show original strikeout price and sales price even only one variation has discount, for both product page and archive page.

    5 Answers

    Avatar: Justin
    Luca Rossi
    Support staff

    Dear @kmc,

    Could you kindly provide some screenshots? We are still not entirely clear about your requests.

    Best regards,
    8Theme Team

    Avatar: kmc
    kmc
    Participant

    Please see attached. You can see from the archive page and product page we cannot see there is actually a discount, unless we select the discounted variation, we can see the strikeout price.

    Please contact administrator
    for this information.
    Files is visible for topic creator and
    support staff only.
    Avatar: Justin
    Luca Rossi
    Support staff

    Hi @kmc,

    Please try adding this custom code under functions.php file locates in your child theme:

    // Display regular price alongside sale price for variable products
    add_filter('woocommerce_variable_sale_price_html', 'custom_variable_sale_price_display', 10, 2);
    add_filter('woocommerce_variable_price_html', 'custom_variable_sale_price_display', 10, 2);
    
    function custom_variable_sale_price_display($price, $product) {
        // Get min and max prices
        $min_regular_price = $product->get_variation_regular_price('min', true);
        $min_sale_price = $product->get_variation_sale_price('min', true);
        $max_regular_price = $product->get_variation_regular_price('max', true);
        $max_sale_price = $product->get_variation_sale_price('max', true);
    
        // Check if product has sale price
        if ($min_sale_price !== $min_regular_price || $max_sale_price !== $max_regular_price) {
            if ($min_sale_price === $max_sale_price && $min_regular_price === $max_regular_price) {
                // Single price (all variations have same price)
                $price = '<del>' . wc_price($min_regular_price) . '</del> <ins>' . wc_price($min_sale_price) . '</ins>';
            } else {
                // Price range - show both regular and sale ranges
                $price = '<del>' . wc_price($min_regular_price) . ' - ' . wc_price($max_regular_price) . '</del> <ins>' . wc_price($min_sale_price) . ' - ' . wc_price($max_sale_price) . '</ins>';
            }
        }
    
        return $price;
    }

    https://prnt.sc/DIZKbO8nW-Bi

    Hope it helps!

    Avatar: kmc
    kmc
    Participant

    Seems still not correct, after I add the code, it only displays one price for the variable product for the archive page and the product page. See attached.

    By right it should still show the original price ranges and strike out, then the discount price range.

    Files is visible for topic creator and
    support staff only.
    Avatar: Justin
    Luca Rossi
    Support staff

    Hi @kmc,

    By default, WooCommerce does not display the original price for variable products.

    If you would like to extend the code provided above, we recommend seeking assistance from tools such as ChatGPT or Claude.AI.

    Please note that custom development falls outside the scope of the standard support services we provide.

    Thank you for your understanding.

    Best regards,
    8Theme’s Team

Want to reply? Log in, or register with your ThemeForest purchase code, to reply to this topic.

Login / Register