Add text before price

I have been trying for several days to add a β€œprice” to the price of a product inside one page of a product for trading. I tried many variations of this code to no avail.

/** Add "Price" before the price */ function price_text() { ?> <div class="price-text"> <p>Price</p> </div> <?php } add_filter('woocommerce_get_price','price_text'); 

This is the closest I have, but it shows the price of $ 0.

I also started adding this piece of code

 '<span class="amount">' . $currency_symbol . $price . '</span>' 

to no avail. but

I am really new to PHP and OPP in general. Any help would be greatly appreciated.

I use the Genesis framework if that matters.

+7
source share
3 answers

A slight improvement for translation.

 /** Add "Price" before the price */ add_filter('woocommerce_get_price','price_text'); function price_text($price) { if ( is_woocommerce()){ ?> <div class="price-text"> <p><?php _e('Price','woothemes'); ?></p> </div> <?php return $price; } else { return $price; } } 
+4
source

Yay

I get it!

 add_filter('woocommerce_get_price','price_text'); function price_text($price) { ?> <div class="price-text"> <p>Price</p> </div> <?php return $price; } 

I just lacked a variable

$price

when declaring a function

price_text

and

 return $price; 

Hope this helps someone :)

Cheers, Mike

+3
source

I added an if else statement so that it only appears on product pages, not on check pages.

 /** Add "Price" before the price */ add_filter('woocommerce_get_price','price_text'); function price_text($price) { if ( is_woocommerce()){ ?> <div class="price-text"> <p>Price</p> </div> <?php return $price; } else { return $price; } } 

Cheers, Mike

+1
source

All Articles