Add Text After the Price in a WooCommerce Product
You can add a bit of static text after the price in a WooCommerce Product by using a woocommerce filter woocommerce_get_price_html.
For the above product I want to add some text just after the price to a certain range of products. Here below is the code to do that:
So I have set my target products in an array and the additional product text as a variable $textafter, if the product is part of that array it will return the prices and also the additional text which also has a CSS class applied for styling. If the product is not part of that array it will just return the price.
This will occur in the listing and detailed view product pages as the $post->ID is also included in the conditional code.
Hi there,
thanks a lot for this snippet. It works fine on my shop and single product pages.
However, the text doesn’t appear with products listed in the cross-sell section of the single product page. Is this somehow possible, please?
Many thanks.
Max
Hi,
Thanks for the great tip! I was wondering is it possible to show different texts on variable products?
For example:
If I select red apple, $4 (for 1 pack)
But if select green apple $4 (for 2 packs)
Thank you
Terence
Hi there.
Thanks for this awesome solution. Like Mark above I’m also having an issue with displaying per category.
What I’d like to do is add the text after a specific category only.
I’ve tried your example and messed around with the code but haven’t got much further.
Any help much appreciated!
Thanks,
Neil
Hi i am trying this on the latest version of woocommerce. But when i add it to my functions.php file the website loads on a blank page, and i have to restore the functions.php file through ftp in order to get it back to normal. Any help?
Does this work with the latest version of woocommerce?
Hello,
What can I do If I want to put this for all my products?
Thank you!
Hi,
Thanks! Awesome snippet. I was wandering if it is possible to put the text next to the price instead of placing it on the next line.
Great snippet thanks very much,
was wondering if its possible to filter this per category ie only for category one, three, and five?
Thanks
Try adjusting the conditional…
if ( in_array( $product_id, $my_product_array ) && in_category( array( 1,3,5 ) ) {
//code goes here
}
hi, thanks for this great snippet..
although the array for the product worked, but the one in the comment for the categories didnt, my snippet is:
function themeprefix_custom_price_message( $price ) {
global $post;
$product_id = $post->ID;
$my_product_array = array(14460,12767);//add in product IDs
if ( in_array( $product_id, $my_product_array ) && in_category( array(268)) ) {
//$textafter = ‘Per day’; //add your text
$monthly_price= get_post_meta(get_the_ID(), ‘monthly_price’, TRUE);
return $price . ‘ ‘ . $monthly_price .” ;
}
else {
return $price ;
}
}
add_filter( ‘woocommerce_get_price_html’, ‘themeprefix_custom_price_message’ );
can you tell whats wrong in it please?
thanks
mark
Was looking how to do this for the website I listed. Great solution thank you.