I am trying to add save amount total on the sale flash badge using this snippet here below but there is something wrong since it is not working. Any advice would be really appreciated.
// Add save amount on the sale badge.
add_filter( 'woocommerce_sale_flash', 'woocommerce_custom_badge', 10, 2 );
function woocommerce_custom_badge( $price, $product ) {
$saved = wc_price( $product->regular_price - $product->sale_price );
return $price . sprintf( __(' <div class="savings">Save %s</div>', 'woocommerce' ), $saved );
}
Thanks
You don't have the correct arguments in your filter (
$price
doesn't exist for example), see here the related source code forwoocommerce_sale_flash
filter hook to understand better:So your working code is going to be something like:
The Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and works.