Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save PrafullaKumarSahu/c8dd96fdebb2bb7a181a to your computer and use it in GitHub Desktop.
Save PrafullaKumarSahu/c8dd96fdebb2bb7a181a to your computer and use it in GitHub Desktop.
UM/EDD Open Metrics: Show various sale stats
// Avg downloads per customer
function sc_edd_avg_downloads_per_customer( $atts ) {
$amount = 0;
$query = new WP_Query( array( 'post_type' => 'download' ) );
foreach( $query->posts as $post ) {
$amount = $amount + edd_get_download_sales_stats( $post->ID );
}
$amount = $amount / edd_count_total_customers();
return number_format( $amount, 2 );
}
add_shortcode( 'edd_avg_downloads_per_customer', 'sc_edd_avg_downloads_per_customer' );
// Avg purchases per customer
function sc_edd_avg_purchases_per_customer( $atts ) {
$amount = edd_get_total_sales() / edd_count_total_customers();
return number_format( $amount, 2 );
}
add_shortcode( 'edd_avg_purchases_per_customer', 'sc_edd_avg_purchases_per_customer' );
// Sales count
function sc_edd_sales( $atts ) {
$amount = 0;
$query = new WP_Query( array( 'post_type' => 'download' ) );
foreach( $query->posts as $post ) {
$amount = $amount + edd_get_download_sales_stats( $post->ID );
}
return $amount;
}
add_shortcode( 'edd_sales', 'sc_edd_sales' );
// Orders count
function sc_edd_orders( $atts ) {
return '<span class="amount">' . edd_get_total_sales() . '</span>';
}
add_shortcode( 'edd_orders', 'sc_edd_orders' );
// Orders count today
function sc_edd_orders_today( $atts ) {
$stats = new EDD_Payment_Stats;
$amount = $stats->get_sales( 0, 'today', false, array( 'publish', 'revoked' ) );
return '<span class="amount">' . $amount . '</span>';
}
add_shortcode( 'edd_orders_today', 'sc_edd_orders_today' );
// Orders count month
function sc_edd_orders_month( $atts ) {
$stats = new EDD_Payment_Stats;
$amount = $stats->get_sales( 0, 'this_month', false, array( 'publish', 'revoked' ) );
return '<span class="amount">' . $amount . '</span>';
}
add_shortcode( 'edd_orders_month', 'sc_edd_orders_month' );
// Avg. order size
function sc_edd_avg_order( $atts ) {
$amount = edd_get_total_earnings() / edd_get_total_sales();
return '$' . '<span class="amount">' . number_format($amount) . '</span>';
}
add_shortcode( 'edd_avg_order', 'sc_edd_avg_order' );
// Avg. spend by customer
function sc_edd_avg_spend_per_customer( $atts ) {
$totals = edd_get_total_earnings();
$customers = edd_count_total_customers();
$amount = $totals / $customers;
return '$' . '<span class="amount">' . number_format( $amount ) . '</span>';
}
add_shortcode( 'edd_avg_spend_per_customer', 'sc_edd_avg_spend_per_customer' );
// Show customers count
function sc_edd_count_total_customers( $atts ) {
return '<span class="amount">' . edd_count_total_customers() . '</span>';
}
add_shortcode( 'edd_count_total_customers', 'sc_edd_count_total_customers' );
// Show today sales
function sc_edd_today_sales( $atts ) {
$stats = new EDD_Payment_Stats;
return '$' . '<span class="amount">' . $stats->get_earnings( 0, 'today', false ) . '</span>';
}
add_shortcode( 'edd_today_sales', 'sc_edd_today_sales' );
// Show monthly sales
function sc_edd_month_sales( $atts ) {
$stats = new EDD_Payment_Stats;
return '$' . '<span class="amount">' . $stats->get_earnings( 0, 'this_month' ) . '</span>';
}
add_shortcode( 'edd_month_sales', 'sc_edd_month_sales' );
// Show total sales
function sc_edd_total_sales( $atts ) {
return '$' . '<span class="amount">' . edd_get_total_earnings() . '</span>';
}
add_shortcode( 'edd_total_sales', 'sc_edd_total_sales' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment