If you have an online store with WooCommerce, sooner or later you might want to add additional text before the prices, especially if you want to highlight on-sale products.
Table of Contents
Text before product price (all products)
In this case, we are going to add some text before the visible price on the product page, here:

The solution is very simple, just add this code, customizing the text you want to be displayed:
/* Prices prefix */
add_filter( 'woocommerce_get_price_html', 'wphelp_price_prefix' );
function wphelp_price_prefix($price){
$text_to_add_before_price = ' LIMITED TIME OFFER ';
return $text_to_add_before_price . $price ;
}
Code language: PHP (php)
What we will get, in all products, would be this:

Text before the product price (only for discounted products)
Now let’s put ourselves in another situation, and that is that you want the text to be displayed only in the discounted products, on sale. In this case, the code would be this one:
/* On sale price prefix */
add_filter( 'woocommerce_get_price_html', 'wphelp_sale_price_prefix', 100, 2 );
function wphelp_sale_price_prefix( $price, $product ) {
if ( $product->is_on_sale() ) {
$text_to_add_before_price = str_replace( '<ins>', '<ins><br>ON SALE ', $price);
return $text_to_add_before_price ;
}else{
return $price;
}
}
Code language: PHP (php)
The result is this, showing the prefix only on discounted products and just in front of the price on offer:

Remember: Your additional text will take YOUR price’s font styles.
How do I add these codes?
To learn how to add the codes check this simple and easy guide:
WordPress guide: How and where to paste PHP, JS, CSS codes and functions
Thank you for the snippets. It’s exactly what I needed.
Now I just need to find out how to hide regular price when the product is on sale.
Do you maybe have a snippet for that? 🙂