Last active
November 21, 2016 23:02
-
-
Save stephywells/e33c2a298f5810136bdb746970614d3e to your computer and use it in GitHub Desktop.
EDD faster downloads page
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 | |
// New function to get the cart details for an array of purchase ids | |
function edd_get_user_payments_cart_detail( $payment_ids, $include_bundle_files = false ) { | |
global $wpdb; | |
$payment_ids = array_filter( $payment_ids, 'is_numeric' ); | |
$payments = $wpdb->get_results("SELECT post_ID, meta_value FROM {$wpdb->postmeta} WHERE meta_key = '_edd_payment_meta' AND post_ID in (" . implode( $payment_ids, ',' ). ")"); | |
$all_details = array(); | |
if ( ! empty( $payments ) ) { | |
foreach ( $payments as $payment ) { | |
$payment_meta = maybe_unserialize( $payment->meta_value ); | |
$payment_id = $payment->post_ID; | |
$cart_details = isset( $payment_meta['cart_details'] ) ? maybe_unserialize( $payment_meta['cart_details'] ) : array(); | |
if ( ! empty( $cart_details ) && is_array( $cart_details ) ) { | |
foreach ( $cart_details as $key => $cart_item ) { | |
// use existing code here L993 - L1034 broken out into a separate function | |
// https://github.com/easydigitaldownloads/easy-digital-downloads/blob/master/includes/payments/functions.php#L993-L1034 | |
} | |
$all_details[ $payment_id ] = apply_filters( 'edd_payment_meta_cart_details', $cart_details, $payment_id ); | |
} | |
} | |
} | |
return $all_details; | |
} | |
// Now, in history-downloads.php, change: | |
$purchases = edd_get_users_purchases( get_current_user_id(), 20, true ); | |
if ( $purchases ) : | |
do_action( 'edd_before_download_history' ); | |
// to: | |
$purchases = edd_get_users_purchases( get_current_user_id(), 20, true ); | |
if ( $purchases ) : | |
$payment_ids = array(); | |
foreach ( $purchases as $payment ) { | |
$payment_ids[] = $payment->ID; | |
} | |
$all_downloads = edd_get_user_payments_cart_detail( $payment_ids, true ); | |
do_action( 'edd_before_download_history' ); | |
// And change: | |
$downloads = edd_get_payment_meta_cart_details( $payment->ID, true ); | |
// to: | |
$downloads = $all_downloads[ $payment->ID ]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment