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 therental_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.