Skip to main content

PHP hook

Complete List of Available PHP Filters for the RNB Plugin

This documentation provides a complete list of available PHP filters in the RNB Plugin. These filters allow developers to customize and extend the functionality of the plugin by hooking into specific points in the code.

Filters Overview

Filters in WordPress allow you to modify data before it is saved or displayed. The following sections outline the filters available in the RNB Plugin, along with examples of how to use them.

Filter Hook rnb_allow_free_booking

The rnb_allow_free_booking filter hook allows developers to control whether free bookings are permitted for a specific rental product.

Usage

In your code, you might use the rnb_allow_free_booking filter to implement custom logic that determines if free booking is allowed based on your specific requirements. Here's how you can use it:

if (empty(apply_filters('rnb_allow_free_booking', true, $posted_data['rental_days_and_costs']['cost'], $product_id))) {
wp_send_json([
'error' => [esc_html__('Free booking is not allowed', 'redq-rental')]
]);
}

Filter Parameters

  • true: The default value of the filter if no other functions are hooked to it. This indicates that free booking is allowed unless modified by other functions.
  • $posted_data['rental_days_and_costs']['cost']: The cost associated with the rental days and costs.
  • $product_id: The ID of the product being checked.

Return Value

The filter should return a boolean value:

  • true: Indicates that free booking is allowed.
  • false: Indicates that free booking is not allowed.

Example

To prevent free bookings for a specific product, you can add a function to the filter hook in your theme's functions.php or a custom plugin:


add_filter('rnb_allow_free_booking', function($allow, $cost, $product_id) {

if ($product_id === 123) { // Example product ID
return false; // Disallow free booking for product ID 123
}

return $allow;

}, 10, 3);

In this example, free booking is disallowed for the product with ID 123, but allowed for other products.

Hook Priority

You can specify the priority when hooking into the rnb_allow_free_booking filter. The default priority is 10, but you can adjust it depending on when you want your custom logic to run.

Notes

  • Ensure you handle the wp_send_json response properly in your frontend code to display the appropriate message to the user.
  • The text domain used in the esc_html__ function should match the text domain of your theme or plugin.

Filter Hook rnb_prepared_price_summary

This filter allows you to modify the price breakdown before it is sent in the AJAX response.

Parameters

  • $item_data (array):
    Array of item data, including product details and pricing.

  • $product_id (int):
    The ID of the product being booked.

  • $posted_data (array):
    The form data submitted for the booking.

Example


add_filter('rnb_prepared_price_summary', function($item_data, $product_id, $posted_data) {
// Add a custom field to the price summary
$item_data['custom_field'] = 'Custom Value';
return $item_data;
}, 10, 3);

Filter Hook rnb_calculate_inventory_data

This filter allows you to modify the final response data for the rnb_calculate_inventory_data AJAX call.

Parameters

  • $response (array):
    The final response data, including quantity, available quantity, total cost, and price breakdown.

  • $posted_data (array):
    The form data submitted for the booking.

    add_filter('rnb_calculate_inventory_data', function($response, $posted_data) {
// Modify the final response data
$response['custom_message'] = 'Inventory data calculated successfully!';
return $response;
}, 10, 2);

Filter Hook rnb_add_cart_item_data

This filter allows you to modify the cart item metadata after the rental data has been added.

Parameters

  • $cart_item_meta (array)
    The cart item metadata, including the rental_data processed from the form submission.

Example

add_filter('rnb_cart_item_meta', function($cart_item_meta) {
// Add custom data to the cart item meta
$cart_item_meta['custom_data'] = 'Custom Value';
return $cart_item_meta;
});

Usage

This method is typically hooked into WooCommerce to add rental-related data to the cart item metadata whenever a product of type redq_rental is added to the cart. It ensures that only new orders (with order_type as new_order) are processed, and that if a quote_id already exists in the rental_data, no further processing is done.

add_filter('woocommerce_add_cart_item_data', 'rnb_add_cart_item_data', 10, 2);

Filter Hook rnb_prepared_cart_item_data

This filter allows you to modify the rental item data that is prepared for display in the WooCommerce cart.

Parameters

  • $item (array)
    The formatted rental item data, including product details and rental information.

  • $product_id (int)
    The ID of the product being rented.

  • $cart_item (array)
    The cart item data, including rental data and quantity.

Example

add_filter('rnb_prepared_cart_item_data', function($item, $product_id, $cart_item) {
// Modify the rental item data before it is displayed in the cart
$item['custom_field'] = 'Custom Value';
return $item;
}, 10, 3);

Filter Hook rnb_ignored_item_meta_keys

This filter allows you to modify the list of meta keys that should be ignored when preparing the cart item data for display. By default, the key pay_during_booking is ignored.

Parameters

  • $ignored_keys (array):
    An array of meta keys that should be ignored when processing cart item data.

  • $meta_data (array):
    The rental item metadata that is being processed.

Example

add_filter('rnb_ignored_item_meta_keys', function($ignored_keys, $meta_data) {
// Add a custom meta key to the ignored list
$ignored_keys[] = 'custom_meta_key';
return $ignored_keys;
}, 10, 2);

This documentation provides details about the apply_filters hooks used in the rnb_get_item_data method, including their parameters and examples for customizing their behavior.

rnb_calculate_rental_cost_args

This filter allows developers to modify the arguments used to calculate rental costs before they are processed by the calculate_rental_cost method.

Parameters

  • $args (array)
    The array of arguments for rental cost calculation, including pickup and return locations, distance cost, categories, resources, additional persons, and deposits.

  • $post_form (array)
    The posted form data from the booking request.

  • $inventory_id (string)
    The ID of the inventory item being booked.

  • $product_id (string)
    The ID of the product being rented.

Example

add_filter('rnb_calculate_rental_cost_args', function($args, $post_form, $inventory_id, $product_id) {
// Adjust the cost based on the custom logic
if ($post_form['custom_condition']) {
$args['distance_cost'] *= 1.2; // Apply a 20% increase
}
return $args;
}, 10, 4);

rnb_prepared_form_data

This filter allows developers to modify the prepared form data before it is returned by the prepare_form_data method. The form data includes all calculated and formatted data related to the booking.

Parameters

  • $data (array): The array of prepared form data, including booking details, quantity, locations, cost breakdown, and other related information.
  • $post_form (array): The posted form data from the booking request.

Example

add_filter( 'rnb_prepare_form_data', 'custom_prepare_form_data', 10, 2 );
function custom_prepare_form_data( $data, $post_form ) {
// Modify the form data
$data['custom_field'] = 'Custom Value';
return $data;
}

This example demonstrates how to use the rnb_prepare_form_data filter to add a custom field to the prepared form data.

redq_pricing_type

This filter allows developers to modify the pricing type of a product after it has been retrieved from the product's meta data.

Parameters

  • $pricing_type (string)
    The pricing type retrieved from the product meta. This value can be customized via the filter.

Example

add_filter('redq_pricing_type', function($pricing_type) {
// Customize the pricing type based on specific conditions
if ($pricing_type === 'hourly') {
$pricing_type = 'custom_hourly_rate';
}
return $pricing_type;
});

Usage

This filter is applied when calling the redq_get_pricing_type method. It allows developers to adjust the pricing type of a product based on custom logic, such as modifying it for specific product categories or user roles.

redq_daily_pricing

This filter allows developers to modify the daily pricing of a product after it has been retrieved from the product's meta data.

Parameters

  • $daily_pricing (string|array)
    The daily pricing data retrieved from the product meta. This value can be customized via the filter.

Example

add_filter('redq_daily_pricing', function($daily_pricing) {
// Customize the daily pricing based on specific conditions
if (is_array($daily_pricing) && isset($daily_pricing['weekend'])) {
$daily_pricing['weekend'] = $daily_pricing['weekend'] * 1.2; // Increase weekend pricing by 20%
}
return $daily_pricing;
});

Usage

This filter is applied when calling the redq_get_daily_pricing method. It allows developers to adjust the daily pricing of a product based on custom logic, such as modifying the pricing for specific days, seasons, or user roles.

redq_monthly_pricing

This filter allows developers to modify the monthly pricing of a product after it has been retrieved from the product's meta data.

Parameters

  • $monthly_pricing (string|array)
    The monthly pricing data retrieved from the product meta. This value can be customized via the filter.

Example

add_filter('redq_monthly_pricing', function($monthly_pricing) {
// Customize the monthly pricing based on specific conditions
if (is_numeric($monthly_pricing)) {
$monthly_pricing = $monthly_pricing * 0.9; // Apply a 10% discount to the monthly pricing
}
return $monthly_pricing;
});

Usage

This filter is applied when calling the redq_get_monthly_pricing method. It allows developers to adjust the monthly pricing of a product based on custom logic, such as offering discounts, adjusting prices for different seasons, or modifying pricing based on user roles.

redq_day_ranges_pricing

This filter allows developers to modify the day ranges pricing plans of a product after they have been retrieved from the product's meta data.

Parameters

  • $day_ranges_pricing_plans (array|string)
    The day ranges pricing plans retrieved from the product meta. This value can be customized via the filter.

Example

add_filter('redq_day_ranges_pricing', function($day_ranges_pricing_plans) {
// Customize the day ranges pricing plans based on specific conditions
if (is_array($day_ranges_pricing_plans)) {
foreach ($day_ranges_pricing_plans as &$plan) {
$plan['price'] *= 1.05; // Increase all day range prices by 5%
}
}
return $day_ranges_pricing_plans;
});

Usage

This filter is applied when calling the redq_get_day_ranges_pricing method. It allows developers to adjust the day ranges pricing plans of a product based on custom logic, such as adjusting prices based on time periods, offering special promotions, or modifying pricing plans based on user-specific criteria.

rnb_payable_pickup_location

This filter allows developers to modify the pickup locations associated with a rental product.

Parameters

  • $pickup_locations (array)
    An array containing pickup location information like title, cost, latitude, longitude, etc.

  • $inventory_id (int|null)
    The inventory ID associated with the pickup locations.

  • $taxonomy (string)
    The taxonomy term related to the pickup locations.

Example

add_filter('rnb_payable_pickup_location', function($pickup_locations) {
// Customize pickup locations
return $pickup_locations;
});

rnb_payable_return_location

This filter allows developers to modify the dropoff locations associated with a rental product.

Parameters

  • $dropoff_locations (array): An array containing dropoff location information, including title, cost, latitude, longitude, etc.
  • $inventory_id (int|null): The inventory ID associated with the dropoff locations. Can be null if not applicable.
  • $taxonomy (string): The taxonomy term related to the dropoff locations.

Example Usage

You can use the rnb_payable_return_location filter in your theme's functions.php file or in a custom plugin to modify the dropoff locations data. Here is an example of how to use this filter:

add_filter('rnb_payable_return_location', function($dropoff_locations) {
// Customize dropoff locations
return $dropoff_locations;
});

In the example above, the filter function receives the $dropoff_locations array. You can modify this array as needed and return the updated data. This allows you to customize the dropoff location details before they are used elsewhere in your application.

Notes

  • Ensure that your callback function properly handles and returns the $dropoff_locations array to avoid unexpected issues.
  • This filter is useful for customizing dropoff location data dynamically based on specific conditions or requirements.

rnb_payable_resources

The rnb_payable_resources filter allows developers to modify the resources associated with a rental product.

Parameters

  • $resources (array): An array containing resource information, such as name, cost, and whether the resource is clickable.
  • $inventory_id (int|null): The inventory ID associated with the resources. Can be null if not applicable.
  • $taxonomy (string): The taxonomy term related to the resources.

Example Usage

You can use the rnb_payable_resources filter in your theme's functions.php file or in a custom plugin to modify the resources data. Here is an example of how to use this filter:

add_filter('rnb_payable_resources', function($resources) {
// Customize resources
return $resources;
});

In the example above, the filter function receives the $resources array. You can modify this array as needed and return the updated data. This allows you to customize the resource details before they are used elsewhere in your application.

You can adjust or expand upon this as needed!

rnb_payable_person

The rnb_payable_person filter allows developers to modify the person-related information associated with a rental product.

Parameters

  • $persons (array): An array containing person-related information, such as cost and type (e.g., adult, child).
  • $inventory_id (int|null): The inventory ID associated with the person-related information. Can be null if not applicable.
  • $taxonomy (string): The taxonomy term related to the person-related information.

Example Usage

You can use the rnb_payable_person filter in your theme's functions.php file or in a custom plugin to modify the person-related data. Here is an example of how to use this filter:

add_filter('rnb_payable_person', function($persons) {
// Customize person-related information
return $persons;
});

In the example above, the filter function receives the $persons array. You can modify this array as needed and return the updated data. This allows you to customize the person-related details before they are used elsewhere in your application.

rnb_payable_security_deposite Filter Hook

The rnb_payable_security_deposite filter allows developers to modify the security deposits associated with a rental product.

Parameters

  • $security_deposites (array): An array containing security deposit information, such as cost, applicability, and hourly cost.
  • $inventory_id (int|null): The inventory ID associated with the security deposits. Can be null if not applicable.
  • $taxonomy (string): The taxonomy term related to the security deposits.

Example Usage

You can use the rnb_payable_security_deposite filter in your theme's functions.php file or in a custom plugin to modify the security deposit data. Here is an example of how to use this filter:

add_filter('rnb_payable_security_deposite', function($security_deposites) {
// Customize security deposits
return $security_deposites;
});

In the example above, the filter function receives the $security_deposites array. You can modify this array as needed and return the updated data. This allows you to customize the security deposit details before they are used elsewhere in your application.

rnb_payable_category Filter Hook

The rnb_payable_category filter allows developers to modify the categories associated with a rental product.

Example Usage

You can use the rnb_payable_category filter in your theme's functions.php file or in a custom plugin to modify the categories data. Here is an example of how to use this filter:

add_filter('rnb_payable_category', function($rnb_categories) {
// Customize categories
return $rnb_categories;
});

In the example above, the filter function receives the $rnb_categories array. You can modify this array as needed and return the updated data. This allows you to customize the categories details before they are used elsewhere in your application.

redq_non_payable_attributes Filter Hook

The redq_non_payable_attributes filter allows developers to modify the array of non-payable attributes associated with a rental product's inventory.

Example Usage

You can use the redq_non_payable_attributes filter in your theme's functions.php file or in a custom plugin to modify the attributes data. Here is an example of how to use this filter:

add_filter('redq_non_payable_attributes', function($attributes) {
// Loop through each inventory's attributes
foreach ($attributes as &$inventory) {
if (isset($inventory['attributes']) && is_array($inventory['attributes'])) {
foreach ($inventory['attributes'] as &$attribute) {
// Customize the attribute name
$attribute['name'] = $attribute['name'] . ' (Custom)';
}
}
}

return $attributes;
});

In the example above, the filter function receives the $attributes array. You can loop through and modify this array as needed, such as appending " (Custom)" to each attribute's name. This allows you to customize the attributes before they are displayed or used elsewhere in your application.

rnb_payable_category

The rnb_payable_category filter allows developers to modify the categories associated with a rental product.

Example Usage

You can use the rnb_payable_category filter in your theme's functions.php file or in a custom plugin to modify the categories data. Here is an example of how to use this filter:

add_filter('rnb_payable_category', function($rnb_categories) {
// Customize categories
return $rnb_categories;
});

In the example above, the filter function receives the $rnb_categories array. You can modify this array as needed and return the updated data. This allows you to customize the categories details before they are used elsewhere in your application.

rnb_product_request_for_quote_text

This filter allows developers to modify the text displayed on the "Request for Quote" button for rental products.

Parameters

  • $button_text (string)
    The default text for the "Request for Quote" button, as retrieved by the get_rfq_button_text() method.

  • $this (object)
    The instance of the class where this method is being called, allowing access to other methods and properties.

Example

add_filter('rnb_product_request_for_quote_text', function($button_text, $instance) {
// Customize the Request for Quote button text
return __('Get a Quote', 'your-text-domain');
}, 10, 2);

Usage

This filter is particularly useful if you want to customize the "Request for Quote" button text based on different conditions, such as product type or user role.

redq_translated_days

This filter allows developers to modify the translated keys for daily pricing. It provides an array of days (e.g., Monday, Tuesday) mapped to their respective pricing values, with the day names translated.

Parameters

  • $translated_days (array)
    An associative array where the keys are translated day names (e.g., 'Monday') and the values are their respective pricing data.

Example

add_filter('redq_translated_days', function($translated_days) {
// Customize the translated days
$translated_days['Monday'] = 100; // Modify Monday pricing
return $translated_days;
});

redq_translated_months This filter allows developers to modify the translated keys for monthly pricing. It provides an array of months (e.g., January, February) mapped to their respective pricing values, with the month names translated.

rnb_order_item_data_key

This function returns the meta key used to store all relevant data for an order item in the RnB (Rental and Booking) plugin. It allows developers to filter and modify the meta key via the rnb_order_item_data_key filter.

Return Value

  • string
    The meta key used to hold order item data. By default, this is 'rnb_hidden_order_meta'.

Filter

  • rnb_order_item_data_key
    Developers can use this filter to change the meta key used to store order item data.

Example

add_filter('rnb_order_item_data_key', function($key) {
// Change the order item data meta key
return 'custom_order_item_meta_key';
});

In this example, the order item meta key is changed to custom_order_item_meta_key using the filter.

rnb_product_price_class

This filter allows developers to modify the CSS class applied to the product price HTML for products of the redq_rental type in the RnB (Rental and Booking) plugin.

Parameters

  • $css_class (string)
    The default CSS class for the product price HTML. The default is generated as "rnb_price_unit_$product_id", where $product_id is the ID of the current product.

  • $product (WC_Product)
    The WooCommerce product object for the current product.

Example

add_filter('rnb_product_price_class', function($css_class, $product) {
// Customize the CSS class for the product price
return $css_class . ' custom-price-class';
}, 10, 2);

In this example, the default CSS class is modified to include an additional custom-price-class.

The filter is applied in the product_price_html method of the RnB plugin, which customizes the price display for redq_rental type products. The filtered CSS class is used within the span element that wraps the price HTML.

$css_class = apply_filters('rnb_product_price_class', "rnb_price_unit_$product_id", $product);

This documentation provides a concise overview of the rnb_product_price_class filter and explains how developers can use it to modify the CSS class applied to the product price HTML.

rnb_breakdown_summary

This filter allows developers to modify the price summary data for a product in the RnB (Rental and Booking) plugin. The price summary is prepared based on the item data, product ID, and posted data, and includes various cost components such as discounts, locations, categories, resources, and other applicable charges.

Parameters

  • $summary (array)
    An associative array where each key corresponds to a specific cost component, and the value is an array containing the summary text, the total amount, and the formatted cost. The structure is as follows:

    [
    'key' => [
    'text' => 'Summary Key',
    'amount' => 100,
    'cost' => '$100.00',
    ],
    ]
### Parameters

- **`$item_data`** (array)
An array containing the item data with details about various cost components.

- **`$product_id`** (int)
The ID of the product for which the price summary is being prepared.

- **`$posted_data`** (array)
An array of posted data relevant to the product booking or rental.

### Example

```php
add_filter('rnb_breakdown_summary', function($summary, $item_data, $product_id, $posted_data) {
// Customize the price summary
$summary['custom_key'] = [
'text' => __('Custom Charge', 'your-textdomain'),
'amount' => 50,
'cost' => wc_price(50),
];
return $summary;
}, 10, 4);

In this example, a custom charge is added to the price summary, with the key 'custom_key', the text 'Custom Charge', and an amount of $50.00.

The rnb_breakdown_summary filter is applied at the end of the prepare_price_summary method, which generates a summary of costs for a product based on the provided item data. This method skips certain keys unless specific conditions are met, such as the presence of discount totals or specific locations.

return apply_filters('rnb_breakdown_summary', $summary, $item_data, $product_id, $posted_data);

This documentation provides a clear overview of the rnb_breakdown_summary filter and how it can be used to customize the price summary for products in the RnB plugin.

rnb_item_price_breakdown

This filter allows developers to modify the price breakdown data for each cart item in the RnB (Rental and Booking) plugin before the deposit is calculated.

Parameters

  • $price_breakdown (array)
    An associative array containing the price breakdown details for a rental item.

Example

add_filter('rnb_item_price_breakdown', function($price_breakdown) {
// Modify the price breakdown data
$price_breakdown['deposit_total'] *= 1.05; // Add a 5% surcharge
return $price_breakdown;
});

rnb_cart_deposit

This filter allows developers to modify the total deposit amount for rental items before it is displayed in the cart and checkout pages.

Parameters

  • $deposit (float): The total deposit amount calculated based on the cart items.

Example

add_filter('rnb_cart_deposit', function($deposit) {
// Apply a discount or surcharge to the deposit
return $deposit * 0.9; // Apply a 10% discount
});

rnb_display_cart_deposit

This filter allows developers to modify the HTML markup used to display the deposit amount in the cart and checkout pages.

Parameters

  • deposit_markup (string): The HTML markup that displays the deposit in the cart or checkout pages.
  • deposit (float): The total deposit amount.

Example

add_filter('rnb_display_cart_deposit', function($deposit_markup, $deposit) {
// Customize the deposit display
return str_replace('Deposit', 'Security Deposit', $deposit_markup);
}, 10, 2);

redq_rental_get_ip

This filter allows developers to modify the IP address detected by the get_the_user_ip method in the RnB (Rental and Booking) plugin. The method determines the user's IP address by checking various server variables and then applies this filter before returning the IP.

Parameters

  • $ip (string)
    The detected IP address, which can be modified by the filter.

Example

add_filter('redq_rental_get_ip', function($ip) {
// Modify the IP address before it is returned
if ($ip === '127.0.0.1') {
$ip = '192.168.1.1'; // Replace local IP with a specific IP
}
return $ip;
});

Usage

The redq_rental_get_ip filter is applied in the get_the_user_ip method, which is responsible for retrieving the user's IP address. This filter provides flexibility for developers to alter the detected IP address if needed.

return apply_filters('redq_rental_get_ip', $ip);

This documentation provides a clear overview of the redq_rental_get_ip filter and how it can be used to customize the IP address returned by the get_the_user_ip method in the RnB plugin.