Last active
December 25, 2015 00:39
-
-
Save sidharrell/6889853 to your computer and use it in GitHub Desktop.
custom espresso_get_total_cost to add amount paid and amount owed for use on payment overview
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 | |
function espresso_get_total_cost_custom($payment_data) { | |
remove_filter('filter_hook_espresso_get_total_cost', 'espresso_get_total_cost'); | |
global $wpdb; | |
//if for some reason attendee_session isn't setin the payment data, set it now | |
if(!array_key_exists('attendee_session',$payment_data) || empty($payment_data['attendee_session'])){ | |
$SQL = "SELECT attendee_session FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id=%d"; | |
$session_id = $wpdb->get_var( $wpdb->prepare( $SQL, $payment_data['attendee_id'] )); | |
$payment_data['attendee_session']=$session_id; | |
} | |
//find all the attendee rows | |
$sql = "SELECT a.final_price, a.quantity, a.amount_pd FROM " . EVENTS_ATTENDEE_TABLE . " a "; | |
$sql .= " WHERE a.attendee_session='" . $payment_data['attendee_session'] . "' ORDER BY a.id ASC"; | |
$tickets = $wpdb->get_results($sql, ARRAY_A); | |
$total_cost = 0; | |
$total_quantity = 0; | |
$amount_pd = 0; | |
//sum up their final_prices, as this should already take into account discounts | |
foreach ($tickets as $ticket) { | |
$total_cost += $ticket['quantity'] * $ticket['final_price']; | |
$total_quantity += $ticket['quantity']; | |
$amount_pd += $ticket['amount_pd']; | |
} | |
// if (!empty($tickets[0]['coupon_code_price'])) { | |
// if ($tickets[0]['use_percentage'] == 'Y') { | |
// $payment_data['total_cost'] = $total_cost * (1 - ($tickets[0]['coupon_code_price'] / 100)); | |
// } else { | |
// $payment_data['total_cost'] = $total_cost - $tickets[0]['coupon_code_price']; | |
// } | |
// } else { | |
// $payment_data['total_cost'] = $total_cost; | |
// } | |
$payment_data['total_cost'] = number_format( $total_cost, 2, '.', '' ); | |
$payment_data['quantity'] = $total_quantity; | |
$payment_data['amount_pd'] = number_format( $amount_pd, 2, '.', '' ); | |
$payment_data['amount_owed'] = number_format( $total_cost-$amount_pd, 2, '.', ''); | |
//printr( $payment_data, '$payment_data' ); | |
return $payment_data; | |
} | |
add_filter('filter_hook_espresso_get_total_cost', 'espresso_get_total_cost_custom',5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment