“You save €10” on sale products
Product pages of items on sale show how much the customer saves, under the price.
<?php
add_action(
'woocommerce_single_product_summary',
static function () {
global $product;
if ( ! $product instanceof WC_Product || ! $product->is_on_sale() || $product->is_type( 'variable' ) ) {
return;
}
$regular = (float) $product->get_regular_price();
$sale = (float) $product->get_sale_price();
if ( $regular > $sale ) {
printf(
'<p class="snipfire-you-save">You save %1$s (%2$d%%)</p>',
wp_kses_post( wc_price( wc_get_price_to_display( $product, array( 'price' => $regular - $sale ) ) ) ),
(int) round( ( $regular - $sale ) / $regular * 100 )
);
}
},
11
);
Good to know
For simple products and classic product templates. Translate “You save”.
In these packs
- WooCommerce: shop and product pages: Badges, price display, tabs and layout for your shop and product pages.