How to display the Total Sales of a Product

TheCartPress provides two mechanism to display the Total Sales of a product. Designers or Theme constructors can use them.

1. Shortcodes

The shortcode, [tcp_total_sales], display the total sales of the current post_id (product id). So it must be used in a product description (content) or into the main loop

You can use it with a parameter: [tcp_total_sales post_id=”999”]. In this case it could be used in any post type (post, product, pages). In this example, the shortcode would display the total sales of product 999.

2. Template functions

Template functions are useful to use in your theme. For example, if you want to display always the total sales in the product description, using the shortcode you’d have to insert it in all product contents. But, using the template function, you can add a call in your theme templates.

Examples:

  • <?php tcp_the_total_sales( $post_id ); ?> Displays the total sales of a given product
  • <?php tcp_the_total_sales(); ?> Displays the total sales of the current product
  • <?php $sales = tcp_get_the_total_sales( $post_id ); ?> Returns the total sales of a given product
  • <?php $sales = tcp_get_the_total_sales(); ?> Returns the total sales of the current product