Here’s my solution:
functions.php
add_filter( 'woocommerce_get_price_html', 'tlw_custom_price', 10, 2 );
function tlw_custom_price() {
global $product;
$saleprice = $product->get_sale_price();
$fullprice = $saleprice + 200;
if ( is_product() ) {
if ( $product->is_on_sale() ) {
if( $product->is_type('simple') || $product->is_type('external') || $product->is_type('grouped') ) {
$regular_price = get_post_meta( $product->get_id(), '_regular_price', true );
$sale_price = get_post_meta( $product->get_id(), '_sale_price', true );
if( !empty($sale_price) ) {
print '<p class="price">' .
'<div class="regular-price">' .
'<h4 class="woocommerce-Price-amount amount">Original price:<br />' . number_format($regular_price, 0, '', ' ') . ' EUR</h4></div>' .
'<h5 class="red">Need it cheaper? Click here!</h5>' .
'<p><button class="show-price-button button blue" onclick="showPrice()">Get my discount</button></p>' .
'<h4 id="hidden-price" class="sale-price">Discount price:<br />' . number_format($sale_price, 0, '', ' ') . ' EUR</h4>' .
'</p>';
}
}
}
}
}
Before </head> tag
<script>
function showPrice() {
var price = document.getElementById("hidden-price");
if (price.style.display === "block") {
price.style.display = "none";
} else {
price.style.display = "block";
}
}
</script>