Is it possible to just fill the shipping address fields with my own values?
For example, I want city field to be filled with "My City" when an event occurs on the checkout page. I know the checkout page uses Knockout JS, but I haven't figured out how to pass values to the fields themselves.
So far, I have jQuery running on the checkout page but writing code:
$('input[name="shippingAddress.city"]').val("My city");
but this does not seem to work.
2 Answers 2
Yes, It is possible. It works fine in my case.
require(['jquery'], function($){
var onDomIsRendered = function(domString) {
return new Promise(function(resolve, reject) {
function waitUntil() {
setTimeout(function() {
if($(domString).length > 0){
resolve($(domString));
}else {
waitUntil();
}
}, 4000);
}
//start the loop
waitUntil();
});
};
onDomIsRendered("#shipping-new-address-form").then(function(element){
$('[name="city"]').val('My city');
});
});
Because Shipping address from update value by event keyup so you can try:
$('input[name="shippingAddress.city"]').val("My city").keyup();