user8972947
user8972947

Reputation:

Replace the sales price with regular in Woocommerce

How can i replace regular price with sale price when sale price exist?
I've tring to use this code

    add_filter( 'woocommerce_format_sale_price', 'dcwd_sale_price', 20, 3 );
function dcwd_sale_price( $price, $regular_price, $sale_price ) {
    return wc_price( $sale_price );}

but when product isn't on sale, the price that is visible is 0.00

Upvotes: 2

Views: 231

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 253784

This is strange as this hook is used exclusively when products are on sale…

May be try the following:

add_filter( 'woocommerce_format_sale_price', 'dcwd_sale_price', 20, 3 );
function dcwd_sale_price( $price, $regular_price, $sale_price ) {
    if( $sale_price > 0 )
        $price = wc_price( $sale_price );

    return $price;
}

Or:

add_filter( 'woocommerce_format_sale_price', 'dcwd_sale_price', 20, 3 );
function dcwd_sale_price( $price, $regular_price, $sale_price ) {
    if( $sale_price > 0 )
        return wc_price( $sale_price );
    else
        return wc_price( $regular_price );
}

Upvotes: 1

Related Questions