# Rates Helper Functions

### function add\_rates($rates) {.....}

#### **Supported hooks**

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

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

add_filter( ‘before_add_rates’, ‘before_add_rates_callback_fun’, 10, 1 );

function before_add_rates_callback_fun($rates) {
 // code
}
```

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

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

add_filter( ‘should_add_rates’, ‘should_add_rates_callback_fun’, 10, 1 );

function should_add_rates_callback_fun($rates) {
    // code
}

```

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

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

add_action('pre.add.rates', 'pre_add_rates_callback_fun', 10, 1);

function pre_add_rates_callback_fun($rates) {
    // code
}
```

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

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

add_action('post.add.rates', 'post_add_rates_callback_fun', 10, 1);

function post_add_rates_callback_fun($rates) {
    // code
}
```

**Usage**

```php
// for use rates helper you need to add this helper on controller or
// you can autoload this helper.
$this->load->helper('includes/rates');

// add a new rate in rates table.
$rate_id = add_rates($rates);
```

**Request Parameters**

Parameters in array format includes following attributes:

| Param                     | Type            | Required | Default | Description                                               |
| ------------------------- | --------------- | -------- | ------- | --------------------------------------------------------- |
| rate\_plan\_id            | Integer         | Yes      | Null    | The rate\_plan\_id  of rate plan table for specific rate. |
| base\_rate                | Integer         |          | Null    | The base\_rate for a specific rate.                       |
| adult\_1\_rate            | Decimal Integer |          | Null    | The adult\_1\_rate for a specific rate.                   |
| adult\_2\_rate            | Decimal Integer |          | Null    | The adult\_2\_rate for a specific rate.                   |
| adult\_3\_rate            | Decimal Integer |          | Null    | The adult\_3\_rate  for a specific rate.                  |
| adult\_4\_rate            | Decimal Integer |          | Null    | The adult\_4\_rate for a specific rate.                   |
| minimum\_length\_of\_stay | Integer         |          | Null    | The additional\_adult\_rate for a specific rate.          |
| closed\_to\_arrival       | Integer         |          | Null    | The closed\_to\_arrival  for a specific rate.             |
| additional\_child\_rate   | Decimal Integer |          | Null    | The additional\_child\_rate for a specific rate.          |
| maximum\_length\_of\_stay | Integer         |          | Null    | The maximum\_length\_of\_stay for specific rate.          |
| closed\_to\_departure     | Integer         |          | Null    | The closed\_to\_departure  for a specific rate.           |
| can\_be\_sold\_online     | Integer         |          | Null    | The can\_be\_sold\_online for a specific rate.            |
| additional\_adult\_rate   | Decimal Integer |          | Null    | The additional\_child\_rate for a specific rate.          |

**Response**

```
Response include following attributes:
if data have added successfully it would return the key of specific rate id.

```

```php
retrun $rate_id;
```

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

### function get\_rate($rate\_id) {....}

#### **Supported hooks**

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

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

add_filter( ‘before_get_rate’, ‘before_get_rate_callback_fun’, 10, 1 );

function before_get_rate_callback_fun($rate_id) {
 // code
}
```

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

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

add_filter( ‘should_get_rate’, ‘should_get_rate_callback_fun’, 10, 1 );

function should_get_rate_callback_fun($rate_id) {
    // code
}

```

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

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

add_action('pre.get.rate', 'pre_get_rate_callback_fun', 10, 1);

function pre_get_rate_callback_fun($rate_id) {
    // code
}
```

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

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

add_action('post.get.rate', 'post_get_rate_callback_fun', 10, 1);

function post_get_rate_callback_fun($rate_id) {
    // code
}
```

**Usage**

```php
// Retrieves rate data based on a rate_id.
$rate_data = get_rate($rate_id);


```

**Request Parameters**

| Param     | Type    | Required | Default | Description                                      |
| --------- | ------- | -------- | ------- | ------------------------------------------------ |
| $rate\_id | integer | yes      | null    | The id of the rate corresponds to the rate table |

**Response**

```php
// $response array includes following attributes:
// $response['rate_plan_id'] : the rate_plan_id of specific rate.
// $response['base_rate'] : the base_rate for specific rate.
// $response['adult_1_rate'] : the adult_1_rate for specific rate.
// $response['adult_2_rate'] : the adult_2_rate for specific rate.
// $response['adult_3_rate'] : the adult_3_rate for specific rate.
// $response['adult_4_rate'] : the adult_4_rate for specific rate.
// $response['additional_adult_rate'] : the additional_adult_rate for specific rate.
// $response['minimum_length_of_stay'] : the minimum_length_of_stay for specific rate.
// $response['closed_to_arrival'] : the closed_to_arrival  for specific rate.
// $response['closed_to_departure'] : the closed_to_departure for specific rate.
// and many more attributes for table rate with rate table.
 
// Successfully response giving an array of rate data.

  Array
  (
    [rate_id] => 2
    [rate_plan_id] => 2
    [base_rate] => 
    [adult_1_rate] => 
    [adult_2_rate] => 
    [adult_3_rate] => 
    [adult_4_rate] => 
    [additional_adult_rate] => 
    [additional_child_rate] => 
    [is_deleted] => 
    [minimum_length_of_stay] => 
    [maximum_length_of_stay] => 
    [minimum_length_of_stay_arrival] => 
    [maximum_length_of_stay_arrival] => 
    [closed_to_arrival] => 
    [closed_to_departure] => 
    [can_be_sold_online] => 1
   )
   
// If there is no rate data for any rate id provided in input or any error will return null. 
```

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

**Supported hooks**

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

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

add_filter( ‘before_get_rates’, ‘before_get_rates_callback_fun’, 10, 1 );

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

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

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

add_filter( ‘should_get_rates’, ‘should_get_rates_callback_fun’, 10, 1 );

function should_get_rates_callback_fun($filter) {
    // code
}

```

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

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

add_action('pre.get.rates', 'pre_get_rates_callback_fun', 10, 1);

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

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

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

add_action('post.get.rates', 'post_get_rates_callback_fun', 10, 1);

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

**Usage**

```php

// Retrieves rate data based on a filter array.
$rate_data = get_rates($filter);
```

**Request Parameters**

parameter array filter required for rate details.

| Param          | Type    | Required | Default | Description                                            |
| -------------- | ------- | -------- | ------- | ------------------------------------------------------ |
| rate\_id       | Integer | Yes      | Null    | The rate id the primary key for a specific rate table. |
| rate\_plan\_id | Integer | Yes      | Null    | The rate plan id for specific rate.                    |

**Response**

```php
// $response array includes following attributes:
// $response['rate_plan_id'] : the rate_plan_id of specific rate.
// $response['base_rate'] : the base_rate for specific rate.
// $response['adult_1_rate'] : the adult_1_rate for specific rate.
// $response['adult_2_rate'] : the adult_2_rate for specific rate.
// $response['adult_3_rate'] : the adult_3_rate for specific rate.
// $response['adult_4_rate'] : the adult_4_rate for specific rate.
// $response['additional_adult_rate'] : the additional_adult_rate for specific rate.
// $response['minimum_length_of_stay'] : the minimum_length_of_stay for specific rate.
// $response['closed_to_arrival'] : the closed_to_arrival  for specific rate.
// $response['closed_to_departure'] : the closed_to_departure for specific rate.

// Successfully response giving you array of rate data.
  Array
(
    [0] => Array
        (
            [rate_id] => 3
            [rate_plan_id] => 1
            [base_rate] => 
            [adult_1_rate] => 20.00
            [adult_2_rate] => 40.00
            [adult_3_rate] => 60.00
            [adult_4_rate] => 80.00
            [additional_adult_rate] => 
            [additional_child_rate] => 
            [is_deleted] => 
            [minimum_length_of_stay] => 
            [maximum_length_of_stay] => 
            [minimum_length_of_stay_arrival] => 
            [maximum_length_of_stay_arrival] => 
            [closed_to_arrival] => 0
            [closed_to_departure] => 0
            [can_be_sold_online] => 1
        )
)

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

### function update\_rates($rates , $rate\_id) {....}

**Usage**

```php
//update rate data based on a update data and rate id.
 update_rates($rates , $rate_id);
```

**Supported hooks**

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

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

add_filter( ‘before_update_rates’, ‘before_update_rates_callback_fun’, 10, 1 );

function before_update_rates_callback_fun($rates , $rate_id) {
 // code
}
```

**Filter name:**  should\_update\_rates\
**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_rates’, ‘should_update_rates_callback_fun’, 10, 1 );

function should_update_rates_callback_fun($rates, $rate_id) {
    // code
}

```

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

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

add_action('pre.update.rates', 'pre_update_rates_callback_fun', 10, 1);

function pre_update_rates_callback_fun($rates, $rate_id) {
    // code
}
```

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

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

add_action('post.update.rates', 'post_update_rates_callback_fun', 10, 1);

function post_update_rates_callback_fun($rates, $rate_id) {
    // code
}
```

**Request Parameters**

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

| Param                     | Type            | Required | Default | Description                                                     |
| ------------------------- | --------------- | -------- | ------- | --------------------------------------------------------------- |
| rate\_id                  | Integer         | Yes      | Null    | The primary key rate id of rate table for specific rate update. |
| rate\_plan\_id            | Integer         | Yes      | Null    | The rate\_plan\_id  of rate plan table for specific rate.       |
| base\_rate                | Integer         |          | Null    | The base\_rate for a specific rate.                             |
| adult\_1\_rate            | Decimal Integer |          | Null    | The adult\_1\_rate for a specific rate.                         |
| adult\_2\_rate            | Decimal Integer |          | Null    | The adult\_2\_rate for a specific rate.                         |
| adult\_3\_rate            | Decimal Integer |          | Null    | The adult\_3\_rate  for a specific rate.                        |
| adult\_4\_rate            | Decimal Integer |          | Null    | The adult\_4\_rate for a specific rate.                         |
| minimum\_length\_of\_stay | Integer         |          | Null    | The additional\_adult\_rate for a specific rate.                |
| closed\_to\_arrival       | Integer         |          | Null    | The closed\_to\_arrival  for a specific rate.                   |
| additional\_child\_rate   | Decimal Integer |          | Null    | The additional\_child\_rate for a specific rate.                |
| maximum\_length\_of\_stay | Integer         |          | Null    | The maximum\_length\_of\_stay for specific rate.                |
| closed\_to\_departure     | Integer         |          | Null    | The closed\_to\_departure  for a specific rate.                 |
| can\_be\_sold\_online     | Integer         |          | Null    | The can\_be\_sold\_online for a specific rate.                  |
| additional\_adult\_rate   | Decimal Integer |          | Null    | The additional\_child\_rate for a specific rate.                |

**Response**

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

### **function delete\_rate(**$rate\_i&#x64;**) {.....}**

**Usage**

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

 delete_rate($rate_id);
```

**Request Parameters**

| Param     | Type    | Required | Default | Description                                      |
| --------- | ------- | -------- | ------- | ------------------------------------------------ |
| $rate\_id | integer | yes      | null    | The id of the rate corresponds to the rate table |

**Response**

```
Response return mixed Either true or null if rate 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/rates-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.
