2016-08-31 3 views
0

Je me demande comment je pourrais passer une variable dans la fonction simpleCart pour différents liens de caisse en fonction du bouton qui est pressé.simpleCart.js URL dynamique dans Javascript

Boutons:

$('.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 , 
     } 
    }); 

Répondre

0

Vous devez éditer le fichier simpleCart.js pour le faire fonctionner où il a SendForm je l'ai changé action = opts.url à la variable globale checkoutlink qui est définie dans ma fonction onclick:

simpleCart.js édité:

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

boutons:

$('.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; 
});