woo-address-book
woo-address-book copied to clipboard
Allow address pre-population on readonly fields
Hello !
I'm using your plugin in order to have several addresses for my clients. Those clients should not be able to edit addresses, so I added a readonly attribute on my checkout fields.
But your script seems to ignore all fields with "readonly" attribute when changing the address used via the billing_address_book and shipping_address_book . I guess it's to avoid resetting Woocommerce fields which are set to readonly, but those seems to be always of the hidden type.
Would it be possible to ignore only hidden inputs with "readonly" attributes ?
Here is a sample code in scripts.js in line 222 :
// Loop through all fields and set values to the form.
Object.keys( response ).forEach( function ( key ) {
let input = $( '#' + key );
if ( input.length > 0 ) {
- if ( input.attr( 'readonly' ) !== 'readonly') {
+ if ( input.attr( 'readonly' ) !== 'readonly' && input.is('[type="hidden"]') ) {
if ( input.is("select") ) {
if ( input.hasClass( 'selectized' ) && input[0] && input[0].selectize ) {
input[0].selectize.setValue( response[key] );
} else {
input.val( response[key] ).trigger( 'change' );
}
} else if ( input.attr("type") === "checkbox" ) {
input.prop( 'checked', response[key] === "1" ).trigger( 'change' );
} else {
input.val( response[key] ).trigger( 'change' );
}
}
} else {
// Handle radio buttons.
let radio_field = $( '#' + key + '_field' );
if ( radio_field.length > 0 ) {
radio_field.find("input[type='radio']").each( function (index, radio_button) {
if ( $(radio_button).val() === response[key] ) {
$(radio_button).prop( 'checked', true ).trigger( 'change' );
}
});
}
}
} );