WooCommerce: How to add a text after the price (suffix) to certain products

woo expert

Imagine that you are selling a product where there may be confusion among customers whether the price is per unit product or per set.

A possible solution would be to change the name of the product, right? But it is not always feasible, or interesting, for marketing, SEO and many other reasons.

In these cases, customizing the display of prices, adding a suffix to the price that clarifies what it refers to, can help your customers and increase your sales.

Well, the solution is simple: add a suffix to the price of the products to avoid confusion.

And as we are not going to add a suffix to all the products in a crazy way, we must configure the code well so that it only affects those products to which we want to add it.

For example:

/* Custom suffix */
add_filter( 'woocommerce_get_price_html', 'wphelp_custom_suffix' );
function wphelp_custom_suffix($price){
global $post;
$product_id = $post->ID;
$product_array = array( 7484,486,235 );//Here the ID of the products to add the suffix
if ( in_array( $product_id, $product_array )) {
$text_after_price = ' Price per unit '; //change the text 
return $price . $text_after_price;
return $price; 
}Code language: PHP (php)

The result of this example code would be as follows:

To adapt the example code to your needs these are the elements that you must change/customize:

  • $product_array = array (); – Between the brackets put, separated by comma, the IDs of the products to which the text after the price will be applied.
  • $text_after_price = ' ' – Between the single quotes put the text you want to appear after the price.

Ideally you should add this code to your customizations plugin, but it will also work if you add it to the end of the functions.php file of your active child theme.

How useful was this post?

Click on a smiley to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

Leave a Comment

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

Scroll to Top