add() public method

Add a customer
Since: 1.0
public add ( array $data = [] ) : int/bool
$data array
return int/bool
示例#1
0
 /**
  * Creates a customer
  *
  * @since  1.0
  * @access public
  *
  * @param  array $data Array of attributes for a customer.
  *
  * @return mixed       False if not a valid creation, Customer ID if user is found or valid creation.
  */
 public function create($data = array())
 {
     if ($this->id != 0 || empty($data)) {
         return false;
     }
     $defaults = array('payment_ids' => '');
     $args = wp_parse_args($data, $defaults);
     $args = $this->sanitize_columns($args);
     if (empty($args['email']) || !is_email($args['email'])) {
         return false;
     }
     if (!empty($args['payment_ids']) && is_array($args['payment_ids'])) {
         $args['payment_ids'] = implode(',', array_unique(array_values($args['payment_ids'])));
     }
     do_action('give_customer_pre_create', $args);
     $created = false;
     // The DB class 'add' implies an update if the customer being asked to be created already exists
     if ($this->db->add($data)) {
         // We've successfully added/updated the customer, reset the class vars with the new data
         $customer = $this->db->get_customer_by('email', $args['email']);
         // Setup the customer data with the values from DB
         $this->setup_customer($customer);
         $created = $this->id;
     }
     do_action('give_customer_post_create', $created, $args);
     return $created;
 }