Let’s say you’re developing a custom sales page or a landing page. A great way to increase your conversion rate is by showing the number of purchases close to the “add to cart” button.

We’ve already seen how to do this on the single product page, but what if you need to show this on a custom page, and therefore you need a shortcode?

Well, this is super easy and I’m currently using the snippet below on my own website, and specifically in the pricing table of my #CustomizeWoo online course sales page. So, here you go – enjoy!

A shortcode to display the number of product sales based on the WooCommerce product ID

PHP Snippet: Display Product ID Total Sales Anywhere (Shortcode)

Simply use [sales id=”123″] where “123” is your product ID to show the number of product sales

/**
 * @snippet       Product Sales by ID - WooCommerce Shortcode
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.6.4
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_shortcode( 'sales', 'bbloomer_sales_by_product_id' );
  
function bbloomer_sales_by_product_id( $atts ) {
	    
	$atts = shortcode_atts( array(
		'id' => ''
	), $atts );
	
	$units_sold = get_post_meta( $atts['id'], 'total_sales', true );
    
	return $units_sold;
    
}
Share:

Leave a Reply