Redirect to Subscription Checkout

Note: This feature will require advanced JavaScript knowledge. This is not part of ReCharge's standard turnkey solution. Before using the JavaScript below, we recommend that you first Use AJAX to add the item to the cart.

In some cases, you may want a button that bypasses the cart page and goes straight to the subscription checkout. Note this code will work best if your store has only subscription products, none that are one-time.

This is the JavaScript redirect to send the window location to the Shopify Subscriptions. Make sure the product is added to the cart first, as a cart token must exist first.

Warning: Depending on how the code is constructed, things can get weird if customers start hitting the back button on their browser.
function get_cookie(name){ return( document.cookie.match('(^|; )'+name+'=([^;]*)')||0 )[2] }
while(token == undefined);

var myshopify_domain='{{ shop.permanent_domain }}'
try { var ga_linker = ga.getAll()[0].get('linkerParam') } catch(err) { var ga_linker ='' }
var customer_param = '{% if customer %}customer_id={{}}&customer_email={{}}{% endif %}'
checkout_url= ""+myshopify_domain+"&cart_token="+token+"&"+ga_linker+"&"+customer_param;


Alternative Solution: Cart Page Redirect

One 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 in between.

<script>$(window).ready(function() {$('[name="checkout"]').click();});</script><br>

Still stuck? How can we help? Still stuck? How can we help?