Customize the Sale flash to percentage
Customize sale flash to display discount percentage.
function woocommerce_sale_flash_from_woo_discount_rules_v2($html, $post, $product){
$discounted_price = apply_filters('advanced_woo_discount_rules_get_product_discount_price_from_custom_price', false, $product, 1, 0, 'discounted_price', true);
if($discounted_price !== false){
$percentage = round( ( ( $product->get_price() - $discounted_price ) / $product->get_price()) * 100 );
$html = '<div class="product-labels labels-rectangular"><span class="onsale product-label">-' . $percentage . '%' . '</span></div>';
}
return $html;
}
add_filter( 'woocommerce_sale_flash', 'woocommerce_sale_flash_from_woo_discount_rules_v2', 101, 3);