January 7, 2021

Display Total Product Sold Quantity to WooCommerce Page

Currently your customers have no idea how many quantity or downloads have been ordered from your WooCommerce site. So in order to apply this change, you can add below code into your child theme’s functions.php file.

This snippet code show you how to display total product sold quantity WooCommerce page.

if ( $units_sold ) echo ‘

‘ . sprintf( __( ‘Units Sold: %s’, ‘woocommerce’ ), $units_sold ) . ‘


/* Display product sold count at shop page */

add_action( ‘woocommerce_after_shop_loop_item’, ‘get_product_sold_count_at_shop’, 9 );

function get_product_sold_count_at_shop() {
global $product;
$sales = $product->get_total_sales();

$text = __( “Total Sold:”, “woocommerce” ) . ‘ ‘;

return $cart_item_name . ‘ – ‘ . $text . $sales;

/*Display product sold count at order page and email notifications */

add_filter( ‘woocommerce_order_item_name’, ‘add_single_excerpt_to_order_item’, 10, 3 );

function add_single_excerpt_to_order_item( $item_name, $item, $is_visible ){
$product = $item->get_product();
$sales = $product->get_total_sales();
$text = __( “Total Sold:”, “woocommerce” ) . ‘ ‘;

return $item_name . ‘ – ‘ . $text . $sales;

/*Display product sold count at admin order edit page */

add_action( ‘woocommerce_before_order_itemmeta’, ‘total_sales_before_order_itemmeta’, 10, 3 );

function total_sales_before_order_itemmeta( $item_id, $item, $product ){
if( ! ( is_admin() && $item->is_type(‘line_item’) ) ) return;

echo ‘

‘ .__( “Total sales” ) . ‘: ‘ . $product->get_total_sales() . ‘


Related Post

Set a specific product price conditionally on Woocommerce single product page & cart

Update 3 (Only for a defined product ID) To make it work as you want to change the simple products prices only on single product pages (without altering archives product prices, related product prices, upsells and cross-sells) if any cart item doesn’t belong to a specific product category. Then you will need all this following […]

WooCommerce Redirect to Custom Thank you Page

The below code allows you to redirect to a custom page after the user has successfully completed a purchase when using WooCommerce plugin. Simply add the below code to the active child theme function.php and replace the URL in the function wp_redirect() to the desired page.

Add Product to Cart if Cart Empty Woocommerce

We can add product to WooCommerce cart using add_to_cart() function with $product_id. Code goes in function.php file of your active child theme (or active theme).

Add an Empty Cart button in WooCommerce

WooCommerce default not provide Empty Cart button but we can two simple steps to add Empty Cart button on cart page. The first one is to add below code in your functions.php file (this file is located in your theme folder): Second step is to add Empty Cart Button after Apply Coupon button. This code […]

Add Extra Tabs on WooCommerce Product Page

You need to add the code to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Code snippets plugin. Please don’t add custom code directly to your parent theme’s functions.php file as this will be wiped entirely when you update the theme. Use the following […]

Reordering Cross-Sells and Up-Sells in WooCommerce

Cross-sells and Up-sells in WooCommerce are a very powerful tool to give suggestions to your customers. You might know that most people who buy product A will probably need product B as well, and you want the customer to know that. How do you do it? You use cross-sells and up-sells. These products are shown […]

Leave a Reply

Your email address will not be published. Required fields are marked *