Last active
November 5, 2015 19:07
-
-
Save ultimatemember/afb94c5b66c63a34d3c1 to your computer and use it in GitHub Desktop.
UM/EDD Open Metrics: Show recent payments
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
// recent payments | |
function sc_edd_recent_payments( $atts ) { | |
$p_query = new EDD_Payments_Query( array( | |
'number' => 12, | |
'status' => 'publish' | |
) ); | |
$payments = $p_query->get_payments(); | |
if ( $payments ) { ?> | |
<div class="table recent_purchases edd-frontend-purchases"> | |
<table> | |
<tbody> | |
<?php | |
$i = 0; | |
foreach ( $payments as $payment ) { | |
$i++; | |
$items = ''; | |
$saved = 0; | |
foreach($payment->cart_details as $k => $arr ) { | |
$saved = $saved + $arr['discount']; | |
$items .= '<span>' . $arr['name'] .'</span>'; | |
} | |
if ( $saved > 0 ) { | |
$discount = '<span class="edd_price_save">— Saved <span>$' . $saved . '</span> on this order with a discount code</span>'; | |
} else { | |
$discount = ''; | |
} | |
$when = human_time_diff( strtotime( $payment->date ), current_time('timestamp') ); | |
$when = '<span class="edd_bought_when">— ' . $when . ' ago</span>'; | |
?> | |
<tr style="<?php if ( $i == count( $payments ) ) { echo 'opacity:0.4;'; } ?> <?php if ( $i == count( $payments ) - 1 ) { echo 'opacity:0.8;'; } ?>"> | |
<td class="edd_order_amount"><span class="edd_price_label"><?php echo edd_currency_filter( edd_format_amount( $payment->total ), edd_get_payment_currency_code( $payment->ID ) ); ?></span></td> | |
<td class="edd_order_label">Someone bought <span class="edd_items_bought"><?php echo $items; ?></span> <?php echo $discount; ?> <?php echo $when; ?></td> | |
</tr> | |
<?php | |
} // End foreach ?> | |
</tbody> | |
</table> | |
</div> | |
<?php } | |
} | |
add_shortcode( 'edd_recent_payments', 'sc_edd_recent_payments' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment