Skip to content

Instantly share code, notes, and snippets.

@amdrew
Last active April 14, 2017 19:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amdrew/9313218 to your computer and use it in GitHub Desktop.
Save amdrew/9313218 to your computer and use it in GitHub Desktop.
Easy Digital Downloads - Show user's purchase history as dashboard widget
<?php
/**
* Register the dasboard widget
*/
function sumobi_edd_register_dashboard_widgets() {
wp_add_dashboard_widget( 'sumobi_edd_purchase_history', __( 'Purchase History', 'edd' ), 'sumbi_edd_purchase_history_widget' );
}
add_action( 'wp_dashboard_setup', 'sumobi_edd_register_dashboard_widgets' );
/**
* Output the widget
*/
function sumbi_edd_purchase_history_widget() {
// Retrieve all purchases for the current user
$purchases = edd_get_users_purchases( get_current_user_id(), 20, false, 'any' );
if ( $purchases ) : ?>
<table id="edd-purchase-history" style="width: 100%;">
<thead>
<tr class="edd_purchase_row">
<?php do_action('edd_purchase_history_header_before'); ?>
<th class="edd_purchase_id" style="text-align: left;"><?php _e('ID', 'edd'); ?></th>
<th class="edd_purchase_date" style="text-align: left;"><?php _e('Date', 'edd'); ?></th>
<th class="edd_purchase_amount" style="text-align: left;"><?php _e('Amount', 'edd'); ?></th>
<th class="edd_purchase_details" style="text-align: right;"><?php _e('Details', 'edd'); ?></th>
<?php do_action('edd_purchase_history_header_after'); ?>
</tr>
</thead>
<?php foreach ( $purchases as $post ) : setup_postdata( $post ); ?>
<?php $purchase_data = edd_get_payment_meta( $post->ID ); ?>
<tr class="edd_purchase_row">
<?php do_action( 'edd_purchase_history_row_start', $post->ID, $purchase_data ); ?>
<td class="edd_purchase_id">#<?php echo absint( $post->ID ); ?></td>
<td class="edd_purchase_date"><?php echo date_i18n( get_option('date_format'), strtotime( get_post_field( 'post_date', $post->ID ) ) ); ?></td>
<td class="edd_purchase_amount">
<span class="edd_purchase_amount"><?php echo edd_currency_filter( edd_format_amount( edd_get_payment_amount( $post->ID ) ) ); ?></span>
<?php if( $post->post_status != 'publish' ) : ?>
<span class="edd_purchase_sep">&nbsp;&ndash;&nbsp;</span>
<span class="edd_purchase_status <?php echo $post->post_status; ?>"><?php echo edd_get_payment_status( $post, true ); ?></span>
<?php endif; ?>
</td>
<td class="edd_purchase_details" style="text-align: right;">
<a href="<?php echo add_query_arg( 'payment_key', edd_get_payment_key( $post->ID ), edd_get_success_page_uri() ); ?>"><?php _e( 'View', 'edd' ); ?></a>
</td>
<?php do_action( 'edd_purchase_history_row_end', $post->ID, $purchase_data ); ?>
</tr>
<?php endforeach; ?>
</table>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p class="edd-no-purchases"><?php _e( 'You have not made any purchases', 'edd' ); ?></p>
<?php endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment