simpleCart.js dynamic URL within Javascript

281 Views Asked by At

I am wondering how I could pass a variable into the simpleCart function for different checkout links depending on which button is pressed.

Buttons:

$('.paypal_checkout').on('click', function(){
    window.checkoutlink = 'http://url.com/paypal';
     simpleCart.checkout();
               return true;
});

$('.stripe_checkout').on('click', function(){
    window.checkoutlink = 'http://url.com/stripe';
     simpleCart.checkout();
               return true;
});

SimpleCart:

    simpleCart({
        checkout: { 
            type: "SendForm" , 
            url: checkoutlink ,
        } 
    });
1

There are 1 best solutions below

0
Jeff On BEST ANSWER

You have to edit the simpleCart.js file to make it work where it has SendForm I changed action = opts.url to the global variable checkoutlink which Is defined within my onclick function:

edited simpleCart.js:

                    action = checkoutlink,
                    method = opts.method === "GET" ? "GET" : "POST";

buttons:

$('.paypal_checkout').on('click', function(){
    window.checkoutlink = 'http://url.com/paypal';
     simpleCart.checkout();
               return true;
});

$('.stripe_checkout').on('click', function(){
    window.checkoutlink = 'http://url.com/stripe';
     simpleCart.checkout();
               return true;
});