How to hide striked out price on Product and Shop page in Dynamic Pricing and Discounts Plugin for WooCommerce? (Code Snippet)

You are here:

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

Price display in Cart page

To know more about the product, checkout ELEX Dynamic Pricing and Discounts Plugin for WooCommerce.

To know more about other features of the plugin, read product setting up article.

Or checkout documentation section for more related articles.

2 Comments

  1. niladri
    Hi Do you want to display both regular price and sale price unstruck? It would be great if you can share screenshots to explain what you are trying to achieve.

Leave a Reply

WordPress Image Lightbox Plugin