This guide allows you to add custom text as a prefix to prices on both the product archive and single product templates. You may wish to highlight to customers information about prices and adding a prefix may be an ideal way to do this.
/**
* Snippet Name: WooCommerce Add Prefix To Prices
* Snippet Author: ecommercehints.com
*/
add_filter( 'woocommerce_get_price_html', 'ecommercehints_add_prefix_to_prices', 10, 2 );
function ecommercehints_add_prefix_to_prices($price, $product) {
$price = 'ONLY ' . $price;
return $price;
}
2 Responses
Hi, thanks for code snippet.
Could you please advise how to make it work only for some particular category?
We need to put Prefix only for products from one category.
Thanks
Hey Artem,
You would need to wrap line 8 in an if statement using the
is_product_category($category)
orhas_term( '$category', 'product_cat' )
function where the argument/variable passed is either the category ID, title, or slug.If you need any further help getting this implemented, drop us a message here for a quote
Cheers