Customize the Sale flash to percentage

Customize Sale flash to display percentage.

function woocommerce_sale_flash_from_woo_discount_rules($html, $post, $product){
    global $flycart_woo_discount_rules;
    if(!empty($flycart_woo_discount_rules)){
        $discounted_price = $flycart_woo_discount_rules->pricingRules->getDiscountPriceOfProduct($product);
        if($discounted_price !== null){
            $product_price = $product->get_price();
            if($product_price > 0){
                $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', 100, 3);