Reputation: 580
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.
Upvotes: 7
Views: 14789
Reputation: 51
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;
}
}
Upvotes: 4
Reputation: 580
I added an if else statement so that it only shows on the product pages and not the checkout 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
Upvotes: 1
Reputation: 580
Yay!
I figured it out!
add_filter('woocommerce_get_price','price_text');
function price_text($price) {
?>
<div class="price-text">
<p>Price</p>
</div>
<?php
return $price;
}
I was just missing the variable
$price
when declaring the function
price_text
and
return $price;
Hope this helps somebody:)
Cheers, Mike
Upvotes: 3