Give_Customer::decrease_purchase_count PHP Method

decrease_purchase_count() public method

Decrease the customer purchase count.
Since: 1.0
public decrease_purchase_count ( integer $count = 1 ) : mixed
$count integer The amount to decrease by.
return mixed If successful, the new count, otherwise false.
    public function decrease_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;
        if ($new_total < 0) {
            $new_total = 0;
        }
        do_action('give_customer_pre_decrease_purchase_count', $count, $this->id);
        if ($this->update(array('purchase_count' => $new_total))) {
            $this->purchase_count = $new_total;
        }
        do_action('give_customer_post_decrease_purchase_count', $this->purchase_count, $count, $this->id);
        return $this->purchase_count;
    }

Usage Example

 /**
  * Decrements customer purchase stats
  *
  * @access  public
  * @since   1.0
  */
 public function decrement_stats($customer_id = 0, $amount = 0.0)
 {
     $customer = new Give_Customer($customer_id);
     if (!$customer) {
         return false;
     }
     $decreased_count = $customer->decrease_purchase_count();
     $decreased_value = $customer->decrease_value($amount);
     return $decreased_count && $decreased_value ? true : false;
 }
All Usage Examples Of Give_Customer::decrease_purchase_count