1

I want to add text before the price on the WooCommerce product catalogue only, which I have working using this code in functions.php:

// Add text before price
function bd_rrp_price_html( $price, $product ) {
    $return_string = 'Rent from: ' . $price;
    return $return_string;
}
add_filter( 'woocommerce_get_price_html', 'bd_rrp_price_html', 100, 2 );

However, the above function is also adding the text before the price on the product detail page, which I do not want...

What would I need to change in the function to get it so it only displays on the product catalogue?

Thanks.

1

1 Answer 1

0

Try this out. Add other conditional tags according to the requirement. Hope it helps.

// Add text before price
function bd_rrp_price_html( $price, $product ) {
    if(is_shop()){
        $price = 'Rent from: ' . $price;
    }
    return $price;
    
}
add_filter( 'woocommerce_get_price_html', 'bd_rrp_price_html', 100, 2 );

enter image description here enter image description here

15
  • Thanks for your reply. This did not work. Text still shows on the product page, as well as the catalogue.
    – jpopuk
    Nov 30, 2022 at 9:50
  • It shouldn't. i have tested on my project. Can you share more details? Nov 30, 2022 at 10:34
  • Sure... on the product page, you have to select a size, to display the price... that is where the text still shows infront... it might be different because it's a variable product?
    – jpopuk
    Nov 30, 2022 at 10:44
  • No, it works in the variable products too. Nov 30, 2022 at 11:04
  • See, I have uploaded the images. On another note Didi you completely replaced my code with yours? Nov 30, 2022 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.