Redirecting directly to subscription checkout
In some cases, you may want a button that bypasses the cart page and goes straight to the subscription checkout. This is useful if you are creating a buy button on a non-product page in Shopify or if you'd like to minimize the number of steps to purchase.
This guide covers how to redirect a customer directly to the subscription checkout from the product or cart page.
Platform:
- Recharge Checkout on Shopify
- Shopify Checkout Integration
Before you start
- This guide requires custom code and is not supported by Recharge as per the design and integration policy. If you require further assistance, work with a third-party developer.
- The starter code offered in this article applies to Shopify's Theme files.
- Follow the steps outlined in Adding an item to the cart with Ajax prior to following the instructions in this guide.
- The following code works best if your store only sells subscription products and does not offer one-time products.
Create a redirect from the product page
Note:
This section only applies to stores using the Recharge Checkout on Shopify.
This is the JavaScript redirect to send the window location to the Recharge checkout page. Make sure the product is added to the cart first, as a cart token must exist for the script to work.
Tip:
The following function should be called as part of a success call (if using AJAX), or added to an event listener, such as a button click.
function reChargeProcessCart() {
function get_cookie(name){ return( document.cookie.match('(^|; )'+name+'=([^;]*)')||0 )[2] }
do {
token=get_cookie('cart');
}
while(token == undefined); var myshopify_domain='{{ shop.permanent_domain }}'
try { var ga_linker = ga.getAll()[0].get('linkerParam') } catch(err) { var ga_linker ='' }
checkout_url= "https://checkout.rechargeapps.com/r/checkout?myshopify_domain="+myshopify_domain+"&cart_token="+token+"&"+ga_linker;
}
Create a redirect from the cart page
An alternative is to still direct people to the cart page, and then on the cart page run an auto-redirect to trigger the checkout button immediately.
You can do so by adding the code below to the cart.liquid
file. Note that this will still cause the cart page to load between the product page and checkout.
<script>$(window).ready(function() {$('[name="checkout"]').click();});</script><br>
Updated 2 months ago