WooCommerce database already stores the number of products sold for you.
Therefore, you may want to show such number on the product page, close to the Add To Cart button. As we’ve seen in my book Ecommerce and Beyond, showing the number of sales for each product can increase your sales conversion rate.
All you need is pasting the following code in your functions.php. Enjoy!
PHP Snippet: Show Total Number of Sales @ WooCommerce Single Product Page
/**
* @snippet Show Total Sales @ WooCommerce Single Product
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible Woo 4.5
* @donate $9 https://businessbloomer.com/bloomer-armada/
*/
add_action( 'woocommerce_single_product_summary', 'bbloomer_product_sold_count', 11 );
function bbloomer_product_sold_count() {
global $product;
$units_sold = $product->get_total_sales();
if ( $units_sold ) echo '<p>' . sprintf( __( 'Units Sold: %s', 'woocommerce' ), $units_sold ) . '</p>';
}