# Customer Helper Functions

### function add\_customer($customer) {.....}

#### **Supported hooks**

**Filter name:**  before\_add\_customer\
**Description:** This filter would be executed before add customer into the database in add\_customer  helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘before_add_customer’, ‘before_add_customer_callback_fun’, 10, 1 );

function before_add_customer_callback_fun($customer) {
 // code
}
```

**Filter name:**  should\_add\_customer\
**Description:** This filter would be executed before add customer into database in add\_customer helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘should_add_customer’, ‘should_add_customer_callback_fun’, 10, 1 );

function should_add_customer_callback_fun($customer) {
    // code
}
```

**hook name:**  pre.add.customer\
**Description:** This hook would be executed before add customer into the database in add\_customer  helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('pre.add.customer', 'pre_add_customer_callback_fun', 10, 1);

function pre_add_customer_callback_fun($customer) {
    // code
}
```

**hook name:**  post.add.customer\
**Description:** This hook would be executed after add customer into the database in add\_customer helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('post.add.customer', 'post_add_customer_callback_fun', 10, 1);

function post_add_customer_callback_fun($customer) {
    // code
}
```

**Usage**

```php
// for use customer helper you need to add this helper on controller or
// you can autoload this helper.

$this->load->helper('includes/customer');

// add a new customer in customer table. And add customer's primary card details. 
$customer_id = add_customer($customer);
```

**Request Parameters**

Parameters in array format includes following attributes:

<table><thead><tr><th>Param</th><th>Type</th><th width="200">Required</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td>customer_name</td><td>Character</td><td>Yes</td><td>Null</td><td>The customer name of a specific customer.</td></tr><tr><td>address</td><td>Character</td><td></td><td>Null</td><td>The address for specific customer.</td></tr><tr><td>city</td><td>Character</td><td></td><td>Null</td><td>The city for a specific customer.</td></tr><tr><td>region</td><td>Character</td><td></td><td>Null</td><td>The region for a specific customer.</td></tr><tr><td>country</td><td>Character</td><td></td><td>Null</td><td>The country for a specific customer.</td></tr><tr><td>postal_code</td><td>Character</td><td></td><td>Null</td><td>The postal_code for a specific customer. </td></tr><tr><td>phone</td><td>Character</td><td></td><td>Null</td><td>The phone number of a specific customer.</td></tr><tr><td>fax</td><td>Character</td><td></td><td>Null</td><td>The fax for a specific customer.</td></tr><tr><td>email</td><td>Character</td><td></td><td>Null</td><td>The email id of specific customer.</td></tr><tr><td>company_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The company_id for specific customer.</td></tr><tr><td>customer_notes</td><td>Character</td><td></td><td>Null</td><td>The customer_notes for a specific customer.</td></tr><tr><td>phone2</td><td>Character</td><td></td><td>Null</td><td>The phone2 second number of a specific customer.</td></tr><tr><td>address2</td><td>Character</td><td></td><td>Null</td><td>The address2 second address of a specific customer.</td></tr><tr><td>customer_type</td><td>Character</td><td></td><td>Null</td><td>The customer_type  for a specific customer.</td></tr><tr><td>is_primary</td><td>Integer</td><td>Yes</td><td>1</td><td>The is_primary if active then customer card add as a primary card for a specific customer.</td></tr><tr><td>card_name</td><td>Character</td><td>Yes</td><td>Null</td><td>The card_name for a specific customer card  details.</td></tr><tr><td>cc_number</td><td>Character</td><td>Yes</td><td>Null</td><td>The cc_number of the card for customer card details.</td></tr><tr><td>cvc</td><td>Character</td><td>Yes</td><td>Null</td><td>The cvc of the card for customer card details.</td></tr><tr><td>cc_expiry_month</td><td>Character</td><td>Yes</td><td>Null</td><td>The cc_expiry_month of the card for customer card details.</td></tr><tr><td>cc_expiry_year</td><td>Character</td><td>Yes</td><td>Null</td><td>The cc_expiry_year of the card for customer card details.</td></tr></tbody></table>

**Response**

```
Response includes the following attributes:
if data have been added successfully it would return the key of specific customer id.
```

```php
return $customer_id;
```

```
if data does not add it will return null.
```

### function get\_customer($customer\_id) {....}

#### **Supported hooks**

**Filter name:**  before\_get\_customer \
**Description:** This filter would be executed before retrieving customer details from database in get\_customer helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘before_get_customer’, ‘before_get_customer_callback_fun’, 10, 1 );

function before_get_customer_callback_fun($customer_id) {
 // code
}
```

**Filter name:**  should\_get\_customer\
**Description:** This filter would be executed before retrieving customer details from database in get\_customer helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘should_get_customer’, ‘should_get_customer_callback_fun’, 10, 1 );

function should_get_customer_callback_fun($customer_id) {
    // code
}
```

**hook name:**  pre.get.customer\
**Description:** This hook would be executed before retrieving customer details from database in get\_customer helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('pre.get.customer', 'pre_get_customer_callback_fun', 10, 1);

function pre_get_customer_callback_fun($customer_id) {
    // code
}
```

**hook name:**  post.get.customer\
**Description:** This hook would be executed after retrieving customer details from database in get\_customer helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('post.get.customer', 'post_get_customer_callback_fun', 10, 1);

function post_get_customer_callback_fun($customer_id) {
    // code
}
```

**Usage**

```php
// Retrieves customer data based on a customer_id.
$customer_data = get_customer($customer_id);
```

**Request Parameters**

| Param         | Type    | Required | Default | Description                                                      |
| ------------- | ------- | -------- | ------- | ---------------------------------------------------------------- |
| $customer\_id | Integer | Yes      | Null    | The primary id of the customer corresponds to the customer table |

**Response**

```php
// Successfully response giving you array of customer data.
Array
(
    [customer_id] => 21
    [customer_name] => vishal solanki
    [address] => 162 banganga
    [city] => indore
    [region] => 
    [country] => india
    [postal_code] => 452007
    [phone] => 45435656657
    [fax] => 
    [email] => 
    [company_id] => 1
    [customer_notes] => 
    [is_deleted] => 0
    [customer_type] => 
    [cc_number] => 
    [cc_expiry_month] => 
    [cc_expiry_year] => 
    [stripe_customer_id] => 
    [customer_type_id] => 1
    [address2] => 
    [phone2] => 36546667667
    [cc_tokenex_token] => 
    [cc_cvc_encrypted] => 
    [customer_fields] => Array
        (
        )

)

//if there is no customer data for any customer id provided in input or any error will return null.
```

### function get\_customers($filter) {.....}

**Supported hooks**

**Filter name:**  before\_get\_customers\
**Description:** This filter would be executed before retrieving customer details from database in get\_customers helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘before_get_customers’, ‘before_get_customers_callback_fun’, 10, 1 );

function before_get_customers_callback_fun($filter) {
 // code
}
```

**Filter name:**  should\_get\_customers\
**Description:** This filter would be executed before retrieving customer details from database in get\_customers helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘should_get_customers’, ‘should_get_customers_callback_fun’, 10, 1 );

function should_get_customers_callback_fun($filter) {
    // code
}

```

**hook name:**  pre.get.customers\
**Description:** This hook would be executed before retrieving customer details from database in get\_customers helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('pre.get.customers', 'pre_get_customers_callback_fun', 10, 1);

function pre_get_customers_callback_fun($filter) {
    // code
}
```

**hook name:**  post.get.customers\
**Description:** This hook would be executed after retrieving customer details from database in get\_customers helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('post.get.customers', 'post_get_customers_callback_fun', 10, 1);

function post_get_customers_callback_fun($filter) {
    // code
}
```

**Usage**

```php
// Retrieves customer data based on a filter array.
$customer_data = get_customers($filter);
```

**Request Parameters**

parameter array filter required for payment details.

| Param          | Type      | Required | Default | Description                                        |
| -------------- | --------- | -------- | ------- | -------------------------------------------------- |
| customer\_name | Character | Yes      | Null    | The customer name for a specific customer details. |
| customer\_id   | Integer   | Yes      | Null    | The customer\_id  for a specific customer.         |
| company\_id    | Integer   | Yes      | Null    | The company\_id for a specific customer.           |
| email          | Character | Yes      | Null    | The email for a specific customer.                 |

**Response**

```php
// $response array includes following attributes:
// $response['customer_name'] : the customer_name of specific customer.
// $response['address'] : the address for specific customer .
// $response['city'] : the is_percentage for specific customer.
// $response['region'] : the region for specific customer.
// $response['country'] : the country for specific customer.
// $response['postal_code'] : the postal_code for specific customer.
// $response['phone'] : the phone for specific customer.
// $response['fax'] : the fax for specific  customer.
// $response['email'] : the email for specific customer.
// $response['customer_notes'] : the customer_notes for specific customer.
// $response['customer_type'] : the customer_type for specific customer.
// $response['address2'] : the customer_notes for specific customer.
// $response['phone2'] : the customer_notes for specific customer.
// $response['is_primary'] : the is_primary for specific customer card details.
// $response['card_name'] : the card_name for specific customer card details.
// $response['cc_number'] : the cc_number for specific customer card details.
// $response['cvc'] : the cvc for specific customer card details.
// $response['cc_expiry_month'] : the cc_expiry_month for specific customer card details.
// $response['cc_expiry_year'] : the cc_expiry_year for specific customer card details.
// and many more attributes for table customer and join with customer card details .

// Successfully response giving you array of customer data.

Array
(
    [0] => Array
        (
            [customer_id] => 21
            [customer_name] => vishal solanki
            [address] => 162 banganga
            [city] => indore
            [region] => 
            [country] => india
            [postal_code] => 452007
            [phone] => 45435656657
            [fax] => 
            [email] => 
            [company_id] => 1
            [customer_notes] => 
            [is_deleted] => 0
            [customer_type] => 
            [cc_number] => 
            [cc_expiry_month] => 
            [cc_expiry_year] => 
            [stripe_customer_id] => 
            [customer_type_id] => 1
            [address2] => 
            [phone2] => 36546667667
            [cc_tokenex_token] => 
            [cc_cvc_encrypted] => 
            [id] => 6
            [is_primary] => 1
            [evc_card_status] => 
            [card_name] => 
            [is_card_deleted] => 0
            [customer_meta_data] => 
        )

)

//If there is no customer data for filter provided in input or any error will return null.
```

### function update\_customers($customer, $customer\_id) {....}

**Usage**

```php
//update customer data based on a update data and customer id.
 update_customer($customer, $customer_id);
```

**Supported hooks**

**Filter name:**  before\_update\_customer\
**Description:** This filter would be executed before update customer into the database in update\_customer  helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘before_update_customer’, ‘before_update_customer_callback_fun’, 10, 1 );

function before_update_customer_callback_fun($customer, $customer_id) {
 // code
}
```

**Filter name:**  should\_update\_customer\
**Description:** This filter would be executed before update rate into database in update\_rates helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘should_update_customer’, ‘should_update_customer_callback_fun’, 10, 1 );

function should_update_customer_callback_fun($customer, $customer_id) {
    // code
}

```

**hook name:**  pre.update.customer\
**Description:** This hook would be executed before update customer into the database in update\_customer helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('pre.update.customer', 'pre_update_customer_callback_fun', 10, 1);

function pre_update_customer_callback_fun($customer, $customer_id) {
    //code
}
```

**hook name:**  post.update.customer\
**Description:** This hook would be executed after update customer into the database in update\_customer helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('post.update.customer', 'post_update_customer_callback_fun', 10, 1);

function post_update_customer_callback_fun($customer, $customer_id) {
    // code
}
```

**Request Parameters**

Request required customer\_id and  array format data includes following attributes:

<table><thead><tr><th>Param</th><th>Type</th><th width="200">Required</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td>customer_name</td><td>Character</td><td>Yes</td><td>Null</td><td>The customer name of a specific customer.</td></tr><tr><td>address</td><td>Character</td><td></td><td>Null</td><td>The address for specific customer.</td></tr><tr><td>city</td><td>Character</td><td></td><td>Null</td><td>The city for a specific customer.</td></tr><tr><td>region</td><td>Character</td><td></td><td>Null</td><td>The region for a specific customer.</td></tr><tr><td>country</td><td>Character</td><td></td><td>Null</td><td>The country for a specific customer.</td></tr><tr><td>postal_code</td><td>Character</td><td></td><td>Null</td><td>The postal_code for a specific customer. </td></tr><tr><td>phone</td><td>Character</td><td></td><td>Null</td><td>The phone number of a specific customer.</td></tr><tr><td>fax</td><td>Character</td><td></td><td>Null</td><td>The fax for a specific customer.</td></tr><tr><td>email</td><td>Character</td><td></td><td>Null</td><td>The email id of specific customer.</td></tr><tr><td>customer_notes</td><td>Character</td><td></td><td>Null</td><td>The customer_notes for a specific customer.</td></tr><tr><td>phone2</td><td>Character</td><td></td><td>Null</td><td>The phone2 second number of a specific customer.</td></tr><tr><td>address2</td><td>Character</td><td></td><td>Null</td><td>The address2 second address of a specific customer.</td></tr><tr><td>customer_type</td><td>Character</td><td></td><td>Null</td><td>The customer_type  for a specific customer.</td></tr></tbody></table>

**Response**

```
Response return mixed Either true or null if customer data is updated then true else null.
```

### **function delete\_**&#x63;ustome&#x72;**(**$customer\_i&#x64;**) {.....}**

**Usage**

```php
// delete a customer data from the customer table. it's a soft delete process only status will change data still existing in the backend database.

 delete_customer($customer_id);
```

**Request Parameters**

| Param         | Type    | Required | Default | Description                                              |
| ------------- | ------- | -------- | ------- | -------------------------------------------------------- |
| $customer\_id | Integer | Yes      | Null    | The id of the customer corresponds to the customer table |

**Response**

```
Response return mixed Either true or null if customer data is deleted then true 
else null.
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.minical.io/coming-soon/access-minical-data-using-helpers/customer-helper-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
