Here’s my version of the code that adds a prefix to the price of products in Woocommerce.
/* Woo Price Prefix */
add_filter( 'woocommerce_get_price_html', 'woo_price_prefix' );
function woo_price_prefix($price) {
if (!empty($price)) {
$prefix_before_price = 'Price: ';
return $prefix_before_price . $price ;
}}
The code goes into the functions.php file of your selected WordPress theme.
There are many published variants of the code that adds the prefix, but they are usually missing the “if (!empty($price))” part. Omitting it results in the prefix appearing in front of the place where the price should be even when the price for the product is not set at all. So on products without the price you get “Price: “. The “if (!empty($price))” removes the prefix in that case.
If you want me to implement this on your WooCommerce installation, feel free to contact me.
Leave a Reply