Find out in this tutorial how to show the total number of sales made with Easy Digital Downloads (EDD) using a custom shortcode.
A very common tactic to convey confidence to new customers is to show that your products have been purchased by many other people. Social proof, if you use it well and honestly, can be a very interesting tool.
In this tutorial you will learn how to show the total number of sales made with EDD.
Here’s how to do it:
Instructions to create a shortcode to display the total number of EDD sales
1. Create the shorcode
Imagine you want to get a text similar to:
With more than X sales behind us.
Add the following code at the end of functions.php or in your functionality plugin:
With this code you make a loop of the downloads created with Easy Digital Downloads and use the
edd_get_download_sales_stats function to get the number of sales for each one and add them up.
If you look at the code, you’ll see that you’re subtracting ‘1’ from the total number of sales to be able to say “more than…” with total accuracy (here you can see my scientific background, ;)) and you add the word ‘sales’ to save having to write it later.
This way, to get the above sentence you would have to write:
“With more than [edd_sales] behind us.”
This is just an example, but you can tailor it to your liking.
2. Customize the shortcode
Go one step further and customize the shortcode according to your needs.
Imagine you want to show the exact number of sales in a list or in a custom dashboard.
In that case you would remove the subtraction (the ‘-1’) and the word you added afterwards (since now you want to enter the data somewhere else).
The snippet would look like this:
3. Enter the shortcode where you want
Finally, just type
[edd_sales] where you want this EDD sales number to be displayed.
- If you are using the classic editor, use the HTML tab to enter the shortcode.
- In case you are already using the WordPress block editor you can add it to the normal paragraph block, the HTML block or the shortcode block. All of them will render the content correctly.
Now you know how to display the number of sales made with Easy Digital Downloads and keep it updated at any point of the website using a shortcode.
Moreover, you’ve seen that with small variations you can customize it so that it fits 100% to your needs.
Now all you have to do is put it into practice. 😉
Any questions? I read you in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉