Skip to content

How to hide striked out price on Product and Shop page on woocommerce?

By Sukesh Das 1 min read

WooCommerce product page showing a struck-out price from dynamic pricing

When you apply discount to product(s), WooCommerce, by default, shows the sale price with regular price stricken out. This characteristic can be seen in shop page, product page, cart page as well as checkout page. With the code snippet given below, you can choose to hide striked out price on product, shop and category page, with the help of our Dynamic Pricing and Discounts plugin for WooCommerce.

Code snippet to hide strike out price on product and shop page

add_filter('woocommerce_get_price_html', "xa_only_sale_price", 99, 2);

function xa_only_sale_price($price, $product)
{
    if(!is_cart() && !is_checkout() && !is_ajax()){
        if ($product->is_type('simple') || $product->is_type('variation')) {
            return regularPriceHTML_for_simple_and_variation_product($price, $product);
        } 
    }
        return $price;            
    
}

function regularPriceHTML_for_simple_and_variation_product($price, $product){
    return wc_price($product->get_price());
}

Following is a screenshot of how the product price will be shown on product page.WooCommerce Dynamic Pricing and Discounts | Price display in Product page

Price display in Product page

Following is a screenshot of how the price will be shown on cart page.

WooCommerce Dynamic Pricing and Discounts | Price display in Cart page

Start the discussion

Questions are welcome. I usually reply within a day. Your email stays private and comments are checked before they appear.

Booking new projects

Want this done for you?

If this article describes your website, send me the details. I reply by email with next steps.

Sukesh Das

Usually replies within 4 hours9 AM to 11 PM, Bangladesh time