skip to Main Content

Search WordPress Code Snippets – Quick Solutions for Developers


How to Show Sale Percentage on Sale Products in WooCommerce

Learn how to display the sale percentage for discounted items in your WooCommerce store to attract more customers.

// Show sale percentage on sale products
add_action( 'woocommerce_after_shop_loop_item_title', 'codebykp_display_sale_percentage', 10 );
function codebykp_display_sale_percentage() {
    global $product;

    if ( $product->is_on_sale() ) {
        $regular_price = $product->get_regular_price();
        $sale_price = $product->get_sale_price();
        $percentage = round( ( ( $regular_price - $sale_price ) / $regular_price ) * 100 );

        echo '<span class="sale-percentage">-' . $percentage . '%</span>';
    }
}

I’m a WordPress developer with 10+ years of experience in WooCommerce and custom plugins. I combine technical expertise with design flair to help you create standout, user-friendly websites. Let’s transform your digital presence!

Back To Top