Home > Software design >  Woocommerce How to replace the sale price of out of stock products but keep the Regular price?
Woocommerce How to replace the sale price of out of stock products but keep the Regular price?

Time:09-25

I am not good at code, and I am stuck in this situation. Our products have 2 prices:

  • The Retail Price
  • The Sale off Price.

I want to replace the Sale off Price of 'Out of stock' Products with 'SOLD OUT' text and still keep the Retail Price, also remove the 'Sale percent' badge on product image.

I'm using Replace displayed price by a text for out of stock WooCommerce products answer code which works great but it replace all Prices to SOLD text and I do not know how to code it to my needs.

CodePudding user response:

add_filter('woocommerce_get_price_html', 'change_sold_out_product_price_html', 100, 2 );
function change_sold_out_product_price_html( $price_html, $product ) {
    if ( ! $product->is_in_stock() ) {
        $regular_price = wc_price($product->get_regular_price());
        $price_html = __($regular_price."SOLD", "woocommerce");
    }
    return $price_html;
}
  • Related