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

Only Allow 1 Product in the Cart WooCommerce

We can set add to cart limit on WooCommerce cart using woocommerce_add_to_cart_validation filter. Add below code on functions.php file to limit your WooCommerce Cart to just 1 product.

How to Add Custom Product Fields in WooCommerce

For add custom fields in woocommerce use following code in your current themes functions.php file. This will display at admin product page. This will display at single Product Page. This will display at Cart and Checkout Page. This will display at order received and admin order Page.

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 […]

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).

How do I change the link of the Return to shop button WooCommerce?

WooCommerce default redirect on shop page when Cart is empty. The filter woocommerce_return_to_shop_redirect makes it easy to change Return to shop link. Code goes in function.php file of your active child theme (or active theme).

Change cart item prices based on custom cart item data in Woocommerce

We need to use 2 different hooks: The first one just as yours without trying to change the price in it. The second one where you will change your cart item price. The code: Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

Leave a Reply

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