* Print total sales of a single product.
function dorzki_display_product_total_sales() {

	global $product;

	$minimum = 10;

	// Get product total sales.
	$total_sales = (int) get_post_meta( $product->get_ID(), 'total_sales', true );

	// Check for minimum threshold.
	if( $total_sales < $minimum ) {
		return false;

	// Print product line.
	printf( '<strong>' . __( 'This product sold %s times!', 'woocommerce' ) . '</strong>', number_format( $total_sales ) );


add_action( 'woocommerce_single_product_summary', 'dorzki_display_product_total_sales', 25 );

Credit: dorzki.co.il

How to use it?

Usually adding functionality to a WordPress site is by creating a plugin.
However you can simply copy the code and paste it in your child theme’s functions.php file at the end of the file, just before ?>.

For JavaScript code you will need to add them to your theme’s main JavaScript file.

Having issues with the code?

If the code doesn’t work or you get an error please let us know in the comments section.
We will do our best to fix it as-soon-as-possible and update the code on this page.


Leave a Reply