Add Text before the price on product pages

10 Jul

Add Text before the price on product pages

Context: You want to add text like “Price” or “Cost” before, price on the product page, you can use, woocommerce_get_price_html filter.

Solution: We can use ‘woocommerce_get_price_html hook to get this done. Placing the code in functions.php file does the work for us.

add_filter( 'woocommerce_get_price_html', 'filter_get_price_html' , 10 );

/**
* Add Text before the price on product pages
* @param  string $html the price html
* @return string
*/
public function filter_get_price_html( $html ) {
return 'Price: ' . $html;
}

Bydr.code.skm

I am backend developer with passion in Web Application development using latest technologies like Laravel, PHP7, React, ECMAScript 6 and WordPress. I prefer spending time analyzing big data with Apache Spark. Apart from that, I do photography.