Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

“You save €10” on sale products

Product pages of items on sale show how much the customer saves, under the price.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Needs WooCommerce
  • Category WooCommerce
  • Tested with WordPress 7.1, WooCommerce 11.1
PHP
<?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

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.