Recent Sales Widget for Easy Digital Downloads
Lists the latest completed Easy Digital Downloads orders on the dashboard with customer email and amount.
Opens WPIDE on
Code
add_action( 'wp_dashboard_setup', function () {
if ( ! function_exists( 'edd_get_orders' ) || ! current_user_can( 'view_shop_reports' ) ) {
return;
}
wp_add_dashboard_widget( 'wpide_edd_recent_sales', 'Recent Sales', function () {
$orders = edd_get_orders( array(
'number' => 8,
'status' => array( 'complete' ),
'type' => 'sale',
'orderby' => 'date_created',
'order' => 'DESC',
) );
if ( ! $orders ) {
echo '<p>No sales yet.</p>';
return;
}
echo '<table class="widefat striped"><tbody>';
foreach ( $orders as $order ) {
printf(
'<tr><td><a href="%1$s">#%2$s</a><br><small>%3$s</small></td><td style="text-align:right">%4$s<br><small>%5$s</small></td></tr>',
esc_url( admin_url( 'edit.php?post_type=download&page=edd-payment-history&view=view-order-details&id=' . $order->id ) ),
esc_html( $order->get_number() ),
esc_html( $order->email ),
esc_html( edd_currency_filter( edd_format_amount( $order->total ), $order->currency ) ),
esc_html( human_time_diff( strtotime( $order->date_created ), time() ) . ' ago' )
);
}
echo '</tbody></table>';
} );
} );
Notes
Needs Easy Digital Downloads 3.0 or newer.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.