Last active
October 18, 2022 23:03
-
-
Save amdrew/9439243 to your computer and use it in GitHub Desktop.
Easy Digital Downloads - Show the total number of sales and downloads in the download details widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Show the number of sales and download count inside the "Download Details" widget | |
*/ | |
function sumobi_edd_show_download_sales() { | |
$sales = edd_get_download_sales_stats( get_the_ID() ); | |
$sales = $sales > 1 ? $sales . ' sales' : $sales . ' sale'; | |
echo '<p>'; | |
echo $sales; | |
echo '<br/>'; | |
echo sumobi_edd_get_download_count( get_the_ID() ) . ' downloads'; | |
echo '</p>'; | |
} | |
add_action( 'edd_product_details_widget_before_purchase_button', 'sumobi_edd_show_download_sales' ); | |
/** | |
* Get the download count of a download | |
* Modified version of edd_get_file_downloaded_count() | |
*/ | |
function sumobi_edd_get_download_count( $download_id = 0 ) { | |
global $edd_logs; | |
$meta_query = array( | |
'relation' => 'AND', | |
array( | |
'key' => '_edd_log_file_id' | |
), | |
array( | |
'key' => '_edd_log_payment_id' | |
) | |
); | |
return $edd_logs->get_log_count( $download_id, 'file_download', $meta_query ); | |
} |
Hello Dear Sumobi,
I am a newbie, I have a store built with EDD. Now I want to show the total downloads count in a part of my website. And it will be a live countdown like Freepik . com does on the footer. Is it possible with this code? And how to use this code? Is it a plugin or I need to put this code in my website? Please help me as I am very much newbie on this EDD.
Thanks in Advance :)
Zak
Hi, did you solve your problem? If you did, then how did you do it?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello Dear Sumobi,
I am a newbie, I have a store built with EDD. Now I want to show the total downloads count in a part of my website. And it will be a live countdown like Freepik . com does on the footer. Is it possible with this code? And how to use this code? Is it a plugin or I need to put this code in my website? Please help me as I am very much newbie on this EDD.
Thanks in Advance :)
Zak