• I tried the following code to add a discount badge ( -xx% ) in a circle on my product images:

    function filter_woocommerce_single_product_image_thumbnail_html( $html, $post_thumbnail_id ) {
        // Get the global product object
        global $product;
        
        // Is a WC product
        if ( is_a( $product, 'WC_Product' ) ) {
            
            // On sale
            $is_on_sale = $product->is_on_sale();
            
            // True
            if ( $is_on_sale ) {
                $rrp_price        = (int) $product->get_regular_price();
                $sale_price       = (int) $product->get_price();
                
                // Greater than
                if ( $rrp_price > $sale_price ) {
                    $discount_amount  = $rrp_price - $sale_price;
                    $discount_percent = '-' . round( ( $discount_amount / $rrp_price ) * 100, 0 ) . '%';
                    $html             = '<span class="wpd-sale-thumbnail"><span class="wpd-sale-badge">' . $discount_percent . '</span>' . $html . '</span>';
                }
            }
        }
     
        return $html;
    }
    add_filter( 'woocommerce_single_product_image_thumbnail_html', 'filter_woocommerce_single_product_image_thumbnail_html', 10, 2 );

    However it does not show? Can i get some guidance as to why that is ?

    • This topic was modified 3 years, 4 months ago by thefrisb.

    The page I need help with: [log in to see the link]

  • The topic ‘Discount badge does not display on product page’ is closed to new replies.