1

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.

mujuonly
  • 11,370
  • 5
  • 45
  • 75
ghadir assadi
  • 15
  • 1
  • 8

1 Answers1

1
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

mujuonly
  • 11,370
  • 5
  • 45
  • 75
  • Hi, thank you for the code. I think this is still for sale flash. Meaning this will appear if there is a sale flash or maybe I'm misunderstanding. but I just checked and I got 50px icon by adding a sale flash date on a product. What I want is totally unrelated custom badge that I can add whenever I want. unrelated to sale flash or any other manner. :) – ghadir assadi May 16 '20 at 08:37