Posted on

How To Show Download Count On Product Page In WooCommerce?

Last updated on April 6, 2021

Show download count on WooCommerce Product Page of your store. It will contribute to your sales pitch. And as the download count will grow, your visitor will get confidence on your product. They will know that other peoples are using your product as well.

If you’re in business of selling digital / downloadable products, you’ll need good number of downloads to increase your sale. Download counts certainly affects purchase behaviour of your visitor. When they see a positive download count, they may consider purchasing your product. These numbers will always keep growing. And it’ll add a great point in pitching your product.

How it’ll look:

Download Count on WooCommerce Product Page - Simple
Download Count on Simple Product page in WooCommerce
Download Count on WooCommerce Product page - Variable
Download Count on Variable Product page in WooCommerce

How to enable download count on WooCommerce product page:

  1. Choose a file which will never be updated during any kind of update, whether it’s WordPress upgrade, plugin updates or theme update. Most commonly it can either be functions.php file of your custom theme or any other file of your custom plugin.
  2. Add following code in that file
    function show_number_of_downloads() {
        global $wpdb, $product;
        $product_id = ( is_object( $product ) && is_callable( array( $product, 'get_id' ) ) ) ? $product->get_id() : 0;
        if ( empty( $product_id ) ) return;
        $product_type = ( is_object( $product ) && is_callable( array( $product, 'get_type' ) ) ) ? $product->get_type() : 'simple';
        if ( 'variable' === $product_type ) {
            $product_ids = $product->get_children();
        } else {
            $product_ids = array( $product_id );
        $how_many_product_ids = count( $product_ids );
        $id_placeholder       = array_fill( 0, $how_many_product_ids, '%d' );
        $count = $wpdb->get_var(
                "SELECT SUM( download_count ) AS count
                    FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions
                    WHERE product_id IN (".implode( ',', $id_placeholder ).")",
        if ( ! empty( $count ) ) {
            echo '<strong>' . esc_html__( 'Total downloads' ) . '</strong>: ' . $count;
    add_action( 'woocommerce_single_product_summary', 'show_number_of_downloads' );

    Note: This code will work with WooCommerce 2.5.0+

  3. Save the file. You’re done!

The above code will work for both simple & variable products. For simple products, it’ll simply show total download counts. But a variable product can have more than a variations & each variations can provide either separate or same downloadable file. Therefore download count of each variations are recorded separately. The above code automatically combines download count of each variations & display on product page.

Learn how to setup Digital/Downloadable Product in WooCommerce.

6 thoughts on “How To Show Download Count On Product Page In WooCommerce?

  1. Awesome tutorial. Thank you.
    How can I show total product views on WooCommerce product page like this? With a little “eye” icon? Can you please help me?

    1. Thank you for your appreciation.

      Here’s one free plugin on WordPress Product View Counter Page Visit Counter

  2. Product View Counter is no longer compatible. Can anyone suggest an alternate option?

  3. Hi,

    Thank you for the snippets, it works great.
    One question, would be how to control the position of where it appears ?
    For now it shows under the price – But I’d like to have it show up under the add to cart button.
    Can you help with the position ?

    Let me know

    1. In the above-mentioned code, replace this line of code
      add_action( 'woocommerce_single_product_summary', 'show_number_of_downloads' );
      with this
      add_action( 'woocommerce_after_add_to_cart_button', 'show_number_of_downloads' );

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.