Created
July 8, 2020 05:10
-
-
Save atikju/69316d5975e05b3eb63e96798c1a4f39 to your computer and use it in GitHub Desktop.
Recharge JS add to cart and redirect to checkout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//recharge redirect to checkout | |
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 ='' } | |
var customer_param = '{% if customer %}customer_id={{customer.id}}&customer_email={{customer.email}}{% endif %}' | |
checkout_url= "https://checkout.rechargeapps.com/r/checkout?myshopify_domain="+myshopify_domain+"&cart_token="+token+"&"+ga_linker+"&"+customer_param; | |
window.top.location.href= checkout_url; | |
} | |
//recharge add to cart | |
function addItemToCart(variant_id, qty, frequency, unit_type) { | |
data = { | |
"id": variant_id, | |
"quantity": qty, | |
"properties": { | |
"shipping_interval_frequency": frequency, | |
"shipping_interval_unit_type": unit_type | |
} | |
} | |
jQuery.ajax({ | |
type: 'POST', | |
url: '/cart/add.js', | |
data: data, | |
dataType: 'json', | |
success: function() { | |
//window.top.location.href = '/cart'; | |
reChargeProcessCart() | |
}, | |
error: function(data){ | |
console.log(data); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment