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

by | Jan 29, 2021 | Tips & Tricks | 0 comments

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

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Let’s Get Started

Ready to make a real change? Let’s get to work!

Sukesh Das

Typically replies within an hour.