/** * Get donor html. * * @access public * @since 1.0 * * @param Give_Payment $payment Contains all the data of the payment * * @return string Data shown in the User column */ public function get_donor($payment) { $customer_id = give_get_payment_customer_id($payment->ID); if (!empty($customer_id)) { $customer = new Give_Customer($customer_id); $value = '<a href="' . esc_url(admin_url("edit.php?post_type=give_forms&page=give-donors&view=overview&id={$customer_id}")) . '">' . $customer->name . '</a>'; } else { $email = give_get_payment_user_email($payment->ID); $value = '<a href="' . esc_url(admin_url("edit.php?post_type=give_forms&page=give-payment-history&s={$email}")) . '">' . esc_html__('(donor missing)', 'give') . '</a>'; } return apply_filters('give_payments_table_column', $value, $payment->ID, 'donor'); }
do_action('give_view_order_details_billing_before', $payment_id); ?> <div id="give-customer-details" class="postbox"> <h3 class="hndle"> <span><?php _e('Donor Details', 'give'); ?> </span> </h3> <div class="inside give-clearfix"> <?php $customer = new Give_Customer(give_get_payment_customer_id($payment_id)); ?> <div class="column-container customer-info"> <div class="column"> <?php echo Give()->html->donor_dropdown(array('selected' => $customer->id, 'name' => 'customer-id')); ?> </div> <div class="column"> <input type="hidden" name="give-current-customer" value="<?php echo $customer->id; ?> " /> </div> <div class="column">
/** * Deletes a Donation * * @since 1.0 * @global $give_logs * * @param int $payment_id Payment ID (default: 0) * @param bool $update_customer If we should update the customer stats (default:true) * * @return void */ function give_delete_purchase($payment_id = 0, $update_customer = true) { global $give_logs; $payment = new Give_Payment($payment_id); $amount = give_get_payment_amount($payment_id); $status = $payment->post_status; $customer_id = give_get_payment_customer_id($payment_id); $customer = new Give_Customer($customer_id); //Only undo purchases that aren't these statuses $dont_undo_statuses = apply_filters('give_undo_purchase_statuses', array('pending', 'cancelled')); if (!in_array($status, $dont_undo_statuses)) { give_undo_purchase(false, $payment_id); } if ($status == 'publish') { // Only decrease earnings if they haven't already been decreased (or were never increased for this payment) give_decrease_total_earnings($amount); // Clear the This Month earnings (this_monththis_month is NOT a typo) delete_transient(md5('give_earnings_this_monththis_month')); if ($customer->id && $update_customer) { // Decrement the stats for the customer $customer->decrease_purchase_count(); $customer->decrease_value($amount); } } do_action('give_payment_delete', $payment_id); if ($customer->id && $update_customer) { // Remove the payment ID from the customer $customer->remove_payment($payment_id); } // Remove the payment wp_delete_post($payment_id, true); // Remove related sale log entries $give_logs->delete_logs(null, 'sale', array(array('key' => '_give_log_payment_id', 'value' => $payment_id))); do_action('give_payment_deleted', $payment_id); }
/** * Reduces earnings and donation stats when a donation is refunded * * @since 1.0 * * @param $payment_id * @param $new_status * @param $old_status * * @return void */ function give_undo_donation_on_refund($payment_id, $new_status, $old_status) { if ('publish' != $old_status && 'revoked' != $old_status) { return; } if ('refunded' != $new_status) { return; } // Set necessary vars $payment_meta = give_get_payment_meta($payment_id); $amount = give_get_payment_amount($payment_id); // Undo this purchase give_undo_purchase($payment_meta['form_id'], $payment_id); // Decrease total earnings give_decrease_total_earnings($amount); // Decrement the stats for the donor $donor_id = give_get_payment_customer_id($payment_id); if ($donor_id) { Give()->customers->decrement_stats($donor_id, $amount); } // Clear the This Month earnings (this_monththis_month is NOT a typo) delete_transient(md5('give_earnings_this_monththis_month')); }
/** * Get the user ID associated with a payment * * @since 1.3 * * @param int $payment_id Payment ID * * @return string $user_id User ID */ function give_get_payment_user_id($payment_id) { $user_id = -1; // check the customer record first $customer_id = give_get_payment_customer_id($payment_id); $customer = new Give_Customer($customer_id); if (!empty($customer->user_id) && $customer->user_id > 0) { $user_id = $customer->user_id; } // check the payment meta if we're still not finding a user with the customer record if (empty($user_id) || $user_id < 1) { $payment_meta_user_id = give_get_payment_meta($payment_id, '_give_payment_user_id', true); if (!empty($payment_meta_user_id)) { $user_id = $payment_meta_user_id; } } // Last ditch effort is to connect payment email with a user in the user table if (empty($user_id) || $user_id < 1) { $payment_email = give_get_payment_user_email($payment_id); $user = get_user_by('email', $payment_email); if (false !== $user) { $user_id = $user->ID; } } return apply_filters('give_payment_user_id', (int) $user_id); }
/** * Render the User Column * * @access public * @since 1.0 * * @param array $payment Contains all the data of the payment * * @return string Data shown in the User column */ public function column_donor($payment) { // $user_id = give_get_payment_user_id( $payment->ID ); $customer_id = give_get_payment_customer_id($payment->ID); $customer = new Give_Customer($customer_id); $view_url = admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $customer_id); $value = '<a href="' . esc_url($view_url) . '" data-tooltip="' . __('Click here to view this Donor\'s profile', 'give') . '">' . $customer->name . '</a>'; return apply_filters('give_payments_table_column', $value, $payment->ID, 'donor'); }
/** * Deletes a Donation * * @since 1.0 * @global $give_logs * @uses Give_Logging::delete_logs() * * @param int $payment_id Payment ID (default: 0) * * @return void */ function give_delete_purchase($payment_id = 0) { global $give_logs; $post = get_post($payment_id); if (!$post) { return; } $form_id = give_get_payment_form_id($payment_id); give_undo_purchase($form_id, $payment_id); $amount = give_get_payment_amount($payment_id); $status = $post->post_status; $donor_id = give_get_payment_customer_id($payment_id); if ($status == 'revoked' || $status == 'publish') { // Only decrease earnings if they haven't already been decreased (or were never increased for this payment) give_decrease_total_earnings($amount); // Clear the This Month earnings (this_monththis_month is NOT a typo) delete_transient(md5('give_earnings_this_monththis_month')); if ($donor_id) { // Decrement the stats for the donor Give()->customers->decrement_stats($donor_id, $amount); } } do_action('give_payment_delete', $payment_id); if ($donor_id) { // Remove the payment ID from the donor Give()->customers->remove_payment($donor_id, $payment_id); } // Remove the payment wp_delete_post($payment_id, true); // Remove related sale log entries $give_logs->delete_logs(null, 'sale', array(array('key' => '_give_log_payment_id', 'value' => $payment_id))); do_action('give_payment_deleted', $payment_id); }