Rental Widget - Advanced Customization
Perform custom actions when a customer interacts with the Rental Widget
Last updated
Perform custom actions when a customer interacts with the Rental Widget
Last updated
Because of the design of Product Rentals Pro's Rental Widget, the options are almost endless with regard to how much you can customize it with custom development.
Product Rentals Pro allows a developer to hook in to events triggered by the PRP Rental Widget, so that custom behaviour can be implemented.
At the moment, the only event emitted from the widget is when an item is added to Cart, but more will be introduced soon, to support even more advanced custom behaviours.
Why would you want to do this? Well, a common example is that you may want to open a Cart Drawer (or Quick-Cart) when an item is added to Cart from the PRP Rental Widget - rather than the default behaviour of visiting the full Cart page.
This can't just be a setting in Product Rentals Pro, because every theme works differently, and can also have various custom code and logic. Some themes may not even have a Cart Drawer. Hence, the default behaviour of the Rental Widget is to visit the Cart page, as we know that exists on every Shopify store and will work reliably.
prp::cart:added
Fired when an item is added to Cart from the Rental Widget
Data provided with the event
Property | Description |
---|---|
Below is a code example for changing the behaviour when a customer adds an item to their Cart using the Rental Widget.
prp::variant:unavailable
Fired when an unavailable variant is selected by the customer. 'Unavailable' can mean:
The Variant set as having 0 units within Product Rentals Pro
A Variant doesn't exist in Shopify, for the combination of options selected.
A Variant has Inventory Tracking on in Shopify, but with an inventory count of 0 or negative, without "Continue selling when out of stock" is on (though we recommend against using Inventory Tracking for rental products)
You can use this to display a custom message, or to automatically switch the options selected, like in the example below.
Below is a code example for switching the 'Condition' option, if a change in the 'Size' option means that there is no available Variant for the previously selection Condition option.
Coming very soon....
The PRP Rental Widget loads directly on your website (unlike some other rental apps) so your website has the ability to manipulate any part of it with code and/or CSS.
With custom code, you can do things like include extra content into an area of the Rental Widget, show/hide certain parts of the Rental Widget when different selections are made by the customer, or include custom form fields.
Whilst Custom Form Fields are planned as a future feature of Product Rentals Pro, you can get most of the way there now by adding some custom code to your website.
Below is an example of adding a "Pickup Time" field to the Rental Widget. When adding to cart, the Pickup Time selection becomes a line item property of the product in the cart and will then display on the Order in Shopify after it's placed by the customer.
The code below will achieve this. In this example, the field is only visible/active when a customer selects a Delivery Method named "Pickup". It injects CSS as part of a new <style>
tag, but this could also easily be included in a CSS file or in the custom CSS field of the PRP Rental Widget settings accessible from your theme editor.
Some PRP customers use the Exclusions feature within Product Rentals Pro to offer customers of purchasing rather than renting an item, all from the one product page.
In this example, we're going to add in some extra information about the Buy Now option above the Add To Cart button, to help customers understand how it works. The information will only appear once the 'Buy Now' option is selected, and will hide if the customer goes back to selecting one of the rental durations (e.g. 4 Days or 8 Days).
This can be achieved with the following code. Please note this is set up for specific naming of this example site. You'll need to adjust it to work on your site with your specific configuration and naming of fields. It is recommended this is done by a web developer. Like the previous Code Example, it injects CSS as part of a new <style>
tag, but this could also easily be included in a CSS file or in the custom CSS field of the PRP Rental Widget settings accessible from your theme editor.
detail.cart
The response from the Cart JSON API after adding the item(s) to Cart. May be more than 1 item added if the Insurance add-on in activated.
detail.whenPrevented.redirect
Defaults to false If you preventDefault() then the Rental Widget won't redirect the customer to the Cart page, however you can override this by setting this value to true.
detail.whenPrevented.dontReset
Defaults to false If you preventDefault() then the Rental Widget will return the Add to Cart button state to disabled and with "Select dates first..." as the button text. You can override this by setting this value to true, in which case the button would remain in disabled state with text "Adding..."