Rental Products developer reference

Filters, actions, functions, shortcodes and the block for customizing Rental Products.

Beka Rice Avatar

Written by

Last updated


Rental Products has filters, actions, functions, shortcodes and a block for customizing how rentals are priced, displayed and checked. This page lists the public ones. Add code with a code snippets plugin or a custom plugin, and test it on a staging site first; see safely adding custom code to your WooCommerce store. If you have questions about these resources, contact support.

Some hooks only run in one handler mode. New installs use the modern handlers; stores that upgraded from a version before 7.0 may be in legacy mode (check which). Hooks marked "legacy mode only" don’t run with the modern handlers.

Filters

All filters are prefixed wcrp_rental_products_.

Pricing

FilterDescription
wcrp_rental_products_advanced_pricingChanges the rental total. Runs only for products with Advanced pricing on. See seasonal and per-night pricing.
wcrp_rental_products_cart_item_priceThe rental cart item price.
wcrp_rental_products_default_rental_optionsThe defaults used when a product’s rental option is empty. Filtering it isn’t recommended, because changed defaults can cause product data issues.
wcrp_rental_products_multiply_addons_total_by_number_of_days_selected_flat_feesWhether flat fee add-ons are multiplied by the number of rental days, when the product’s Multiply add-ons total by number of days selected is on. Default true.
wcrp_rental_products_multiply_addons_total_by_number_of_days_selected_percentage_basedWhether percentage-based add-ons are multiplied by the number of rental days too. Default false.

Cart and orders

FilterDescription
wcrp_rental_products_cart_group_rentalsReturn true to sort rental items in the cart by start date, grouping rentals with the same dates. Default false.
wcrp_rental_products_reserve_stock_for_unpaid_ordersReturn false to reserve rental stock only once an order is paid. See reserve stock only when orders are paid.
wcrp_rental_products_order_add_rental_products_urlThe address the Add rental product(s) button opens on the order screen. Legacy mode only.

Security deposits

FilterDescription
wcrp_rental_products_cart_fees_disable_security_depositsReturn true to skip security deposits for a cart, for example for certain customers or cart contents. Receives the cart.
wcrp_rental_products_include_security_deposits_for_bundled_itemsReturn true to also charge the deposits of products inside a rental bundle. By default only the bundle’s own deposit is charged.

Dates and calendars

FilterDescription
wcrp_rental_products_rental_date_formatA date format for rentals, instead of the WordPress date format.
wcrp_rental_products_rental_time_formatA time format for rentals, instead of the WordPress time format.
wcrp_rental_products_rental_form_first_dayThe rental form calendar’s first day of the week, instead of the WordPress Week Starts On setting.
wcrp_rental_products_rentals_dashboard_calendar_first_dayThe Rentals » Calendar first day of the week, instead of the WordPress setting.
wcrp_rental_products_litepicker_languageThe language code for the rental form and availability checker calendars. Defaults to the WordPress language.
wcrp_rental_products_rentals_dashboard_calendar_event_nameThe event titles on Rentals » Calendar, also used in the calendar feed. Receives the name, the event data, whether it’s public (the feed) and the calendar mode. Leave out identifying information when the event is public.
wcrp_rental_products_calendar_feed_simple_event_time_overrideA time, such as 09:00, for calendar feed events in simple mode, which otherwise have no time and sit at the top of the day.

Rental form and product display

FilterDescription
wcrp_rental_products_rental_form_after_quantity_enabled_hook_priorityThe hook priority of the rental form when Position is After the product quantity field. See rental form position.
wcrp_rental_products_rental_form_after_quantity_disabled_hook_priorityThe hook priority of the rental form when Position is Before the product quantity field.
wcrp_rental_products_rental_form_total_prefixThe text before the total in the rental form.
wcrp_rental_products_rental_form_total_days_parenthesisWhether the total days in the rental form are shown in parentheses.
wcrp_rental_products_rental_form_total_days_as_weeksReturn true to show the rental form’s total days as weeks. Legacy mode only.
wcrp_rental_products_rental_price_htmlThe rental price HTML on shop and product pages.
wcrp_rental_products_rental_price_display_prefixThe Price prefix setting.
wcrp_rental_products_rental_price_display_suffixThe Price suffix setting.
wcrp_rental_products_rental_information_titleThe rental information tab’s Title setting.
wcrp_rental_products_select_dates_button_htmlThe Select dates button HTML on shop pages.

Labels

Each label on the Rentals » Settings » Labels tab has a filter named after it: wcrp_rental_products_text_ plus the label’s name in lowercase with underscores. For example, wcrp_rental_products_text_rent_from filters Rent from, wcrp_rental_products_text_security_deposit filters Security deposit and wcrp_rental_products_text_part_of_bundle filters Part of bundle. Each receives the text from the settings.

Actions

ActionDescription
wcrp_rental_products_rental_form_after_rental_totalsFires in the rental form after the total price line, before the in-person and return notices. Modern handlers only.

Functions

These functions are kept for compatibility and are available in both modes.

FunctionReturns
wcrp_rental_products_advanced_configuration()Array of the values set in the Advanced configuration setting
wcrp_rental_products_availability_checker_data()Array of the dates and quantity the customer selected in the availability checker
wcrp_rental_products_check_availability()Availability status string
wcrp_rental_products_default_rental_options()Array of the default rental options
wcrp_rental_products_is_rental_only()True or false
wcrp_rental_products_is_rental_purchase()True or false
wcrp_rental_products_order_has_rentals()True or false
wcrp_rental_products_rental_date_format()Rental date format string
wcrp_rental_products_rental_form_date_format()Rental form date format string
wcrp_rental_products_rental_form_first_day()First day of the week set for the rental form
wcrp_rental_products_rental_form_maximum_date()The maximum date, or number of days, the rental form allows
wcrp_rental_products_rental_time_format()Rental time format string

JavaScript events

EventDescription
wcrp_rental_products_product_rental_form_updateFires when the rental form updates on the product page. Legacy mode only.

Shortcodes and block

  • [wcrp_rental_products_availability_checker]: the availability checker. The Availability Checker block (wcrp-rental-products/availability-checker, in the Rental Products block category) does the same.
  • [wcrp_rental_products_rental_purchase_toggle]: the rental or purchase toggle, for product templates where it doesn’t show automatically. See rental or purchase toggle.

Rental Products has no REST API endpoints or WP-CLI commands.

Seasonal and per-night pricing

The wcrp_rental_products_advanced_pricing filter lets you change a rental’s total, for example by the dates chosen. It runs only for products whose Advanced pricing option is On, or set to Use default from rental settings while the store default under Rentals » Settings » Advanced is on. With advanced pricing on, customers can’t change that item’s quantity in the cart, and the price shown near the product title doesn’t reflect your code.

The filter receives:

  • $total: the calculated total for the quantity (price × quantity), after any total override and pricing tier.
  • $data: an array including rent_from and rent_to (dates as YYYY-MM-DD), quantity, product_id, variation_id (for variations), return_days_threshold, and the product page’s query parameters prefixed _GET_.

Return the new total for the quantity.

Rental Products counts calendar days, so Monday to Thursday is four days. To charge per night instead (three nights for Monday to Thursday) on a product priced per day, scale the total by nights over days:

add_filter( 'wcrp_rental_products_advanced_pricing', function( $total, $data ) {
	$days = (int) round( ( strtotime( $data['rent_to'] ) - strtotime( $data['rent_from'] ) ) / DAY_IN_SECONDS ) + 1;
	if ( $days > 1 ) {
		$total = $total / $days * ( $days - 1 );
	}
	return $total;
}, 10, 2 );

This assumes a Period product with a 1-day pricing period and no pricing tiers or total overrides. The calendar still shows calendar days.

Reserve stock only when orders are paid

By default, an order reserves its rental stock as soon as it’s placed, whatever its payment status. To reserve stock only once an order reaches a paid status, add:

/**
 * Reserve rental stock only when orders are paid.
 * Unpaid orders won't block availability for other customers.
 *
 * @link https://kestrelwp.com/docs/how-rental-availability-works/#reserve-stock-only-when-orders-are-paid
 */
add_filter( 'wcrp_rental_products_reserve_stock_for_unpaid_orders', '__return_false' );

What changes for your orders, the admin and customers is explained in how rental availability works. Read it before you add the snippet.

Rental form position

The rental form is added to product pages with WooCommerce hooks, depending on the Position setting:

  • After the product quantity field: woocommerce_after_add_to_cart_quantity, priority 10.
  • Before the product quantity field: woocommerce_before_add_to_cart_button, priority 9. It uses this hook, not woocommerce_before_add_to_cart_quantity, so it sits before WooCommerce Product Add-Ons fields, which use the same hook at priority 10.

To move the form among other elements on those hooks, change its priority with the two hook priority filters above. Fields from other plugins, such as a variable product’s options or Product Add-Ons fields, are positioned by those plugins.

Rental product pages get body classes you can target with CSS: wcrp-rental-products-is-rental on every rental product, plus -is-rental-only, -is-rental-purchase, -is-rental-purchase-rental, -is-rental-purchase-purchase and -is-rental-bundle (each prefixed wcrp-rental-products).

Cookies

The availability checker sets three cookies, for 30 days, to remember a customer’s choices. Include them in your cookie policy.

CookieStores
wcrp_rental_products_availability_checker_rent_fromThe start date selected
wcrp_rental_products_availability_checker_rent_toThe end date selected
wcrp_rental_products_availability_checker_quantityThe quantity selected

Advanced configuration

Rentals » Settings » Advanced » Performance & debugging has an Advanced configuration field for diagnostic options. Only fill it in when Rental Products support gives you a value to use, and remove it when you’re done. wcrp_rental_products_advanced_configuration() returns what’s set.

Retired with the modern handlers

These hooks are only read in legacy mode. With the modern handlers they have no effect:

  • wcrp_rental_products_in_person_pick_up_return_same_day_overlaps. Same-day in-person handovers for rentals longer than a day are always allowed.
  • The filters that changed which page elements the legacy rental form reads (the add to cart button and product and variation ID inputs). The modern rental form reads the product from the form itself.
  • wcrp_rental_products_order_add_rental_products_url, wcrp_rental_products_rental_form_total_days_as_weeks and the JavaScript event wcrp_rental_products_product_rental_form_update, as marked above.

Keep learning