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.
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.
Activate the plugin through the “Plugins” menu in WordPress. Go to “WooCommerce > Settings > Custom Price Labels”.
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.
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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With