Need help displaying custom labels before prices in Woocommerce

Visual Mock Up of labels

Good Afternoon StackExchange;

I am needing a bit of help on figuring how the proper php code to achieve the label set up on various products throughout my woocommerce store.

Basically what I am wanting to do is that on Simple Product(s) I want a label to be displayed before the price that says: “Sale Price:”. I was able to achieve this using this code:

// Add labels before the sale price on product pages

add_filter( 'woocommerce_get_price_html', 'price_before_label' );

function price_before_label( $price ) {
    // Your additional text in a translatable string
    $text = __('Sale Price:');

    // returning the text before the price
    return $text . ' ' . $price;

And you can see a live example at this URL:

This is working as I want it too currently, how ever I need the label to be different on Variable Product(s).

I am wanting the first label to say “Price Range:” and the second to remain the same “Sale Price:”.

Currently it is repeating the same line of text twice. You can see a live example of it at this URL:

I will also add a visual mock up of what I am trying to achieve just so it makes sense to everyone reading:

And on top of all of this, I have a few products where the price is left blank and that is replaced with a custom label that says: “Call for price”, how ever currently it is reading like this: “Sale Price: Call for price”.

I am needing a way so that the label will only be displayed on products that have a price entered, and if it’s left blank then these custom labels that display before the price should not display.

You can view a live example at this URL:

Thank you in advanced for the help!

Read more here:: Need help displaying custom labels before prices in Woocommerce

Leave a Reply

Your email address will not be published. Required fields are marked *