Hello friends,
I’m trying to work out the easiest way to add a discount code in the URL of the checkout page. This code needs to:
Read the ID’s of the items in the cart (2 of them)
if the Id’s equal “id”:7132835971221 or “id”:7132874375317
Then the Javascript needs to append “&discount=BF3” to the end of the checkout URL.
I have no sample code for reading the product ID’s in the cart, but here’s the current code for building the checkout URL.
function buildCheckoutUrl(options) {
// Build the Checkout URL
var checkout_url = 'https://' + options.checkout_domain + '/r/checkout?',
url_params = [
'myshopify_domain=' + options.permanent_domain,
];
url_params = url_params
.concat(get_cart_token())
.concat(get_ga_linker());
return checkout_url + url_params.join('&');
}
I’ve gotten as far as
jQuery.getJSON(‘/cart.js’, function(cart) {GET ID HERE??} );
And then I assume I need to .concat("discount=BF3) in the url_params??
but I just don’t have the Javascript knowledge to figure out what i’m doing. Hopefully somebody can assist me with this…
Cheers.