Hi all,
I am working on adding additional fields at checkout for Shopify plus, a little stuck and not sure why the checkout.attributes are not bringing in the data in the order? Just wondering if anyone has knowledge on this or if they can spot where I am going wrong.
I am using local storage and generated the fields with this tool: https://ui-elements-generator.myshopify.com/pages/cart-attribute
$(document).on(`page:load page:change`, function() {
if (Shopify.Checkout.step == 'contact_information'){
//create text input variable
var delivery_note =
'' +
'' +
'
' +
'
'+
' ' +
'
' +
'' +
' ' +
'
' +
'
' +
'
Authorised to leave to leave package unattended?
' +
'' +
'
';
//append Purchase Order html content
$(".section--contact-information:first").after(delivery_note);
//listen for changes on the text input
// $('.no_input').prop('checked', true);
var obj_yes = $("#yes_checked").val();
var obj_no = $("#no_checked").val();
$(".yes label").on("click", function() {
$(".yes").toggleClass("active");
$(".no").removeClass("active");
$('.yes_input').prop('checked', true);
$('.no_input').prop('checked', false);
//store value in session storage
sessionStorage.setItem("yes_checked", obj_yes);
sessionStorage.removeItem("no_checked");
});
$(".no label").on("click", function() {
$(".no").toggleClass("active");
$(".yes").removeClass("active");
$('.no_input').prop('checked', true);
$('.yes_input').prop('checked', false);
//store value in session storage
sessionStorage.setItem("no_checked", obj_no);
sessionStorage.removeItem("yes_checked");
});
// Store the yes value
var savedObjYes = sessionStorage.getItem("yes_checked");
if (savedObjYes !== null) {
$("#yes_checked").val(savedObjYes);
$(".yes").addClass("active");
}
// Store the no value
var savedObjNo = sessionStorage.getItem("no_checked");
if (savedObjNo !== null) {
$("#no_checked").val(savedObjNo);
$(".no").addClass("active");
}
// Other
$("#CartSpecialInstructions").change(function(){
console.log("i'm changing");
var obj_delivery = $("#CartSpecialInstructions").val();
//store value in session storage
sessionStorage.setItem("devliery_order_note", obj_delivery);
});
var savedObjDelivery = sessionStorage.getItem("devliery_order_note");
if (savedObjDelivery !== null) {
$("#CartSpecialInstructions").val(savedObjDelivery);
}
}
});