Search code examples
wordpresswoocommercecustomizationbadgequalified

How to add custom icon badge for qualified products in WordPress


I found the following code allows you to add custom image badge for sale

<php
    add_filter( 'woocommerce_sale_flash', 'my_custom_sales_badge' );
    function my_custom_sales_badge() {
    $img = '<span class="onsale"><img src="http://yourwebsite.com/wp-content/uploads/2014/11/custom- 
    sales-badge.png" /></span>';
    return $img;
}
CSS
span.onsale {
    background: none;
    box-shadow: none;
}

This code is not related to sale flash products. What I would like to do is to add a customize icon as a badge for qualified products. I assumed that I just find the right argument for add_filter but I didn't find anything.


Solution

  • add_filter( 'woocommerce_product_thumbnails', 'my_custom_sales_badge' );
    
    function my_custom_sales_badge() {
        $img = '<span class="onsale"><img src="https://via.placeholder.com/50" /></span>';
        echo $img;
    }
    
    add_filter('wp_footer', 'add_style_to_badge');
    
    function add_style_to_badge(){
        ?>
    <style>
            span.onsale {
        background: none;
        box-shadow: none;
        float:right;
    }
    </style>
    <?php
    }
    

    Add this into your active theme functions.php