Display Total Product Sold Quantity to WooCommerce Page

Display Total Product Sold Quantity to WooCommerce Page
958 Views
4.3
(62)

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

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

<?php 
/* Display product sold count at product page */ 

add_action( 'woocommerce_single_product_summary', 'cxc_get_product_sold_count_at_product', 11 ); 

function cxc_get_product_sold_count_at_product() { 
	global $product;
	$units_sold = $product->get_total_sales();
	if ( $units_sold ) echo '<p>' . sprintf( __( 'Units Sold: %s', 'cxc-codexcoach' ), $units_sold ) . '</p>';
}

/* Display product sold count at shop page */ 

add_action( 'woocommerce_after_shop_loop_item', 'cxc_get_product_sold_count_at_shop', 9 );

function cxc_get_product_sold_count_at_shop() {
	global $product;
	$sales = $product->get_total_sales();
	?>
	<p><?php echo "($sales items sold)"; ?></p>
	<?php
}

/*Display product sold count at cart and checkout page */

add_filter( 'woocommerce_cart_item_name', 'cxc_get_product_sold_count', 20, 3 );

function cxc_get_product_sold_count( $cart_item_name, $cart_item, $cart_item_key ){
	$product = $cart_item['data'];
	$sales = $product->get_total_sales();
	$text = __( "Total Sold:", "cxc-codexcoach" ) . ' ';

	return $cart_item_name . ' - ' . $text . $sales;
}

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

add_filter( 'woocommerce_order_item_name', 'cxc_add_single_excerpt_to_order_item', 10, 3 );

function cxc_add_single_excerpt_to_order_item( $item_name, $item, $is_visible ){
	$product = $item->get_product();
	$sales = $product->get_total_sales();
	$text = __( "Total Sold:", "cxc-codexcoach" ) . ' ';

	return $item_name . ' - ' . $text . $sales;
}

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

add_action( 'woocommerce_before_order_itemmeta', 'cxc_total_sales_before_order_itemmeta', 10, 3 );

function cxc_total_sales_before_order_itemmeta( $item_id, $item, $product ){
	if( ! ( is_admin() && $item->is_type('line_item') ) ) return;

	echo '<p><em>' .__( "Total sales" ) . ': ' . $product->get_total_sales() . '</em></p>';
}
?>

FAQ

How do I display sold products Number in WooCommerce?

Dear, please paste that code into the function.php file. code is given below.

Does WooCommerce keep track of sales?

Yes, WooCommerce keeps track of sales.

How useful was this blog?

Click on a star to rate it!

Average rating 4.3 / 5. Vote count: 62

No votes so far! Be the first to rate this blog.

  • CodexCoach

    - Web Development Expert

    CodexCoach is a skilled tech educator known for easy-to-follow tutorials in coding, digital design, and software development. With practical tips and interactive examples, CodexCoach helps people learn new tech skills and advance their careers.

Leave a comment

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