Woo Discount Rules: To add Product Sale Text block in WPGridBuilder

Add a product sale text block in WPGridBuilder using Woo Discount Rules.

// Register a custom block for display priduct sale text (without html)
if (!function_exists('awdr_display_product_sale_flash')) {
    function awdr_display_product_sale_flash() {
        // To get the post object.
        $object = wpgb_get_object();
        if (!isset($object->post_type)) {
            return;
        }
    
        // To get the product object.
        $product = function_exists('wc_get_product') ? wc_get_product($object->ID) : null;
        if (!is_object($product)) {
            return;
        }
    
        // To display sale percentage or text
        echo strip_tags(apply_filters('woocommerce_sale_flash', __('Sale!', 'woocommerce'), $object, $product));
    }

    // Register block for sale text (without html)
    add_filter('wp_grid_builder/blocks', function($blocks) {
        $blocks['awdr_product_sale_text'] = [
            'name'            => 'Product Sale Text',
            'render_callback' => 'awdr_display_product_sale_flash',
        ];
        return $blocks;
    });
}