Below is a guide on how to create permacart links with selling plans so that customers can easily checkout products and selling plans pre-populated.
Prerequisites:
- Shopify store link
- Quantity of variant to add
- Shopify Variant IDs
- Shopify Selling Plan IDs
- Browser console
Steps:
- Navigate to your online store and open up the console
- If creating a permalink for a single variant, within the console, add the following code below. Within the GetURL parameters, add the correct respective shopify store name, id, quantity, and selling plan.
- To get the variant ID, within Shopify, click into the product, and at the end of the URL after /products/{{productID}}, type .json and enter. You will see the different product variant IDs
- To get the selling plan ID, navigate to the Smartrr admin portal > Subscription Programs > Click into the subscription program you’d like to add > and save the selling plan Id. For example, if a plan is gid://shopify/SellingPlan/12345, we need the 12345:
function GetURL(shopName, id, quantity, sellingPlan) {
var addURL = `/cart/add?id=${id}&quantity=${quantity}&selling_plan=${sellingPlan}`;
var finalURL = `${shopName}/cart/clear?return_to=${encodeURIComponent(addURL)}`;
console.log(finalURL);
}
GetURL("https://store-name.myshopify.com", "id", "quantity", "sellingPlan")
// example below:
// GetURL("https://store-name.myshopify.com", "46131570180379", 2, "68937144579")
- If creating a permalink for multiple variants and/or multiple selling plans, within the console, add the following code:
function GetURL(shopName, variants) {
var items = [];
for (var i = 0; i < variants.length; i++) {
var variant = variants[i];
items.push(
`items[][id]=${variant.id}&items[][quantity]=${variant.quantity}&items[][selling_plan]=${variant.sellingPlan}`
);
}
var itemsPart = items.join('&');
var addURL = `/cart/add?${itemsPart}`;
var finalURL = `${shopName}/cart/clear?return_to=${encodeURIComponent(addURL)}`;
console.log(finalURL);
}
// Example usage with multiple variants
var variants = [
{ id: 'variant_id_1', quantity: 2, sellingPlan: 'selling_plan_1' },
{ id: 'variant_id_2', quantity: 1, sellingPlan: 'selling_plan_2' },
];
// example variants
// var variants = [
// { id: '46131570180379', quantity: 2, sellingPlan: '68937144579' },
// { id: '46131570132321', quantity: 1, sellingPlan: '68937144579' },
// ];
GetURL("https://store-name.myshopify.com", variants);
- After completing step 2 or 3 based on your needs, the console should return a link holding the items in the cart for the customer to checkout with.
We also recorded a video to guide merchants through how to find the necessary information to create these cart permalinks.