Aldo U
Aldo U

Reputation: 15

Hide strike through price (regular price) but leave the style of sale price unchanged

I'm trying to use a code snippet that I found here in Stackoverlow to hide the strike-through price.

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

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

}

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

It does what it should but the result also deletes the styling of the sale price (different color than regular price). Is there a way to amend above-mentioned code snippet and maintain the sale price styling or should it be done through CSS? Thank you in advance.

Upvotes: 0

Views: 1221

Answers (1)

mujuonly
mujuonly

Reputation: 11861

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

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

}

function wt_regular_price_for_product($price, $product){
    
    if($product->get_sale_price()){
        $price = '<ins>' . ( is_numeric( $product->get_sale_price() ) ? wc_price( $product->get_sale_price() ) : $product->get_sale_price() ) . '</ins>'. $product->get_price_suffix();
    }
    return $price;
}

Upvotes: 1

Related Questions