Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add text before the price

Tags:

woocommerce

I've been trying for days to add "price" before the product price inside woo commerce single product page. I've 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've got, but it shows the price being $0.

I've also started to add 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 am using the Genesis framework if that makes a difference.

like image 717
mchavezi Avatar asked Dec 01 '12 14:12

mchavezi


People also ask

How do I add text above price in WooCommerce?

Create a callback function with the text you want to add before the price. The callback function should pass the $price parameter and add the new text before returning the new price. Save these changes and check the frontend if it works.

How do I add a price tag in WordPress?

Activate the plugin through the “Plugins” menu in WordPress. Go to “WooCommerce > Settings > Custom Price Labels”.

How do I get the price on WordPress?

The get_regular_price() method will return the product regular price, the get_sale_price() will return the product sale price (discounted price), the get_price() returns the product's active price and the get_price_html() returns the product price in HTML format.


1 Answers

A little improvement to be translatable.

/** 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;
    }
}
like image 53
Barbio Avatar answered Oct 21 '22 18:10

Barbio