This article guides developers on enabling a subscription widget on the custom page having multiple product selection, allowing customers to opt in for subscriptions or one-time purchases from the same page.
Here are a few BYOB custom page designs for reference:
Layout 1:
Layout 2:
Step by step guide to get started:
Navigate to themes and search for the main file from where the entire build a box page is getting rendered.
Write a custom javascript and create an empty array and push all the unique product id's of the line items you have got in the build a box page. In case you have the same subscription plans for all your products than any one of the product id also works.
var boxProducts = ["456789078998","45676217309484"]
Do a POST request on Plans API for respective products by sending the
boxProductsarray in the request to fetch all the selling plans.In case of a successful response, create an array of objects and add the below params while looping in through the plans:
[{
plan_name: "Monthly Plan",
selling_plan_id:"691927580946"
}]Loop through the array of object created above and show a dropdown on the sidebar with the subscription plan names based on your design requirements.
Bind an event on the add to cart CTA and the moment customer clicks on that call add.js API from Shopify, pass the selected selling plan id if customer selects subscription option and if they are opting in for one time purchase you don't have to pass selling plan id. On success redirect them to the cart page or checkout.
https://shopify.dev/api/ajax/reference/cart#add-a-selling-plan
Eg:https://{{shop.permanent_domain}}/cart/add.js
You are all set now. Test out the flow on a preview theme and if everything looks fine you can make it live. In case any technical assistance is required feel free to initiate a live chat from your Recurpay Dashboard.
Facing any issue with setting this up? Click the green chat button on Recurpay dashboard or write us at help@recurpay.com




