Give_Customer::decrease_value PHP Method

decrease_value() public method

Decrease a customer's lifetime value.
Since: 1.0
public decrease_value ( float $value ) : mixed
$value float The value to decrease by.
return mixed If successful, the new value, otherwise false.
    public function decrease_value($value = 0.0)
    {
        $new_value = floatval($this->purchase_value) - $value;
        if ($new_value < 0) {
            $new_value = 0.0;
        }
        do_action('give_customer_pre_decrease_value', $value, $this->id);
        if ($this->update(array('purchase_value' => $new_value))) {
            $this->purchase_value = $new_value;
        }
        do_action('give_customer_post_decrease_value', $this->purchase_value, $value, $this->id);
        return $this->purchase_value;
    }

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_value