php - WooCommerce display saved amount on product page
one text
Solution:
You don't see the currency simply because you get it but you don't print it.
Also you can use the wc_price()
function to print the formatted price (with currency) according to your shop settings.
You can optimize your code like this:
add_action( 'woocommerce_single_product_summary', 'usteda_popust', 11 );
function usteda_popust() {
global $product;
if ( $product->is_type('simple') || $product->is_type('external') || $product->is_type('grouped') ) {
if ( $product->get_sale_price() ) {
$amount_saved = $product->get_regular_price() - $product->get_sale_price();
?>
<p style="font-size:18px;color:red;">Ušteda: <?php echo wc_price( $amount_saved ) ?></p>
<?php
}
}
}
The code has been tested and works. Add it to your active theme's functions.php.
Here is the result:
Source