Give_Customer::increase_purchase_count PHP Method

increase_purchase_count() public method

Increase the purchase count of a customer.
Since: 1.0
public increase_purchase_count ( integer $count = 1 ) : integer
$count integer The number to increment by.
return integer The purchase count.
    public function increase_purchase_count($count = 1)
    {
        // Make sure it's numeric and not negative.
        if (!is_numeric($count) || $count != absint($count)) {
            return false;
        }
        $new_total = (int) $this->purchase_count + (int) $count;
        do_action('give_customer_pre_increase_purchase_count', $count, $this->id);
        if ($this->update(array('purchase_count' => $new_total))) {
            $this->purchase_count = $new_total;
        }
        do_action('give_customer_post_increase_purchase_count', $this->purchase_count, $count, $this->id);
        return $this->purchase_count;
    }

Usage Example

Esempio n. 1
0
/**
 * Complete a purchase aka donation
 *
 * Performs all necessary actions to complete a purchase.
 * Triggered by the give_update_payment_status() function.
 *
 * @since  1.0
 *
 * @param  int    $payment_id The ID number of the payment.
 * @param  string $new_status The status of the payment, probably "publish".
 * @param  string $old_status The status of the payment prior to being marked as "complete", probably "pending".
 *
 * @return void
 */
function give_complete_purchase($payment_id, $new_status, $old_status)
{
    // Make sure that payments are only completed once
    if ($old_status == 'publish' || $old_status == 'complete') {
        return;
    }
    // Make sure the payment completion is only processed when new status is complete
    if ($new_status != 'publish' && $new_status != 'complete') {
        return;
    }
    $payment = new Give_Payment($payment_id);
    $creation_date = get_post_field('post_date', $payment_id, 'raw');
    $payment_meta = $payment->payment_meta;
    $completed_date = $payment->completed_date;
    $user_info = $payment->user_info;
    $customer_id = $payment->customer_id;
    $amount = $payment->total;
    $price_id = $payment->price_id;
    $form_id = $payment->form_id;
    do_action('give_pre_complete_purchase', $payment_id);
    // Ensure these actions only run once, ever
    if (empty($completed_date)) {
        give_record_sale_in_log($form_id, $payment_id, $price_id, $creation_date);
        do_action('give_complete_form_donation', $form_id, $payment_id, $payment_meta);
    }
    // Increase the earnings for this form ID
    give_increase_earnings($form_id, $amount);
    give_increase_purchase_count($form_id);
    // Clear the total earnings cache
    delete_transient('give_earnings_total');
    // Clear the This Month earnings (this_monththis_month is NOT a typo)
    delete_transient(md5('give_earnings_this_monththis_month'));
    delete_transient(md5('give_earnings_todaytoday'));
    // Increase the donor's purchase stats
    $customer = new Give_Customer($customer_id);
    $customer->increase_purchase_count();
    $customer->increase_value($amount);
    give_increase_total_earnings($amount);
    // Ensure this action only runs once ever
    if (empty($completed_date)) {
        // Save the completed date
        $payment->completed_date = current_time('mysql');
        $payment->save();
        /**
         * Fires after a donation successfully complete.
         *
         * @since 1.6
         *
         * @param int $payment_id The ID of the payment.
         */
        do_action('give_complete_purchase', $payment_id);
    }
}
All Usage Examples Of Give_Customer::increase_purchase_count