Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to send discount code from cart page to checkout page in shopify?

How we can send discount code from cart page to checkout page? I am trying to add discount code on cart page in hidden field and want to use it on checkout page automatically. I also don't want to enter discount code on checkout page manually.

I have discount code on cart page and I am trying to put it into hidden filed with the help of javascript. following is my code:

$.ajax({
    type: "GET",        
    url: url,
    data: data,
    contentType: "application/json",
    headers: {  'Access-Control-Allow-Origin': '*' },
    success: function(data) {
    var dcv = data.discountCode;
    console.log(dcv);
    document.getElementById("quantityDiscount").value = 'dcv';
   }
});   

from above Ajax call, I received discount code in my dcv variable and put it on input field having #quantityDiscount as id. following is my input filed where I am trying to save this discount code.

<input  id="quantityDiscount" class="js-form-discount" type="hidden" name="discount" value="" >

Please look at this issue and help me to solve it.

Thanks in advance!

like image 274
Vikas Ghai Avatar asked Dec 06 '25 19:12

Vikas Ghai


1 Answers

for sending it to checkout page

localStorage.setItem("discount", dcv);
// Retrieve
localStorage.getItem("discount"); 

console.log(localStorage.getItem("discount"))   // your discount value
sessionStorage.setItem("discount", dcv);
// Retrieve
sessionStorage.getItem("discount"); 

console.log(sessionStorage.getItem("discount"))   // your discount value
  • The localStorage and sessionStorage properties allow to save key/value pairs in a web browser.

  • The sessionStorage object stores data for only one session (the data is deleted when the browser tab is closed).

like image 171
Akash Kumar Verma Avatar answered Dec 09 '25 13:12

Akash Kumar Verma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!