woocommerce ajax load billing address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function ( $ ) { | |
$( 'button.load_customer_billing' ).off( 'click' ); | |
$( 'button.load_customer_billing' ).on( 'click', function() { | |
if ( window.confirm( woocommerce_admin_meta_boxes.load_billing ) ) { | |
// Get user ID to load data for | |
var user_id = $( '#customer_user' ).val(); | |
if ( ! user_id ) { | |
window.alert( woocommerce_admin_meta_boxes.no_customer_selected ); | |
return false; | |
} | |
var data = { | |
user_id: user_id, | |
type_to_load: 'billing', | |
action: 'woocommerce_get_customer_details', | |
security: woocommerce_admin_meta_boxes.get_customer_details_nonce | |
}; | |
$( this ).closest( '.edit_address' ).block({ | |
message: null, | |
overlayCSS: { | |
background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', | |
opacity: 0.6 | |
} | |
}); | |
$.ajax({ | |
url: woocommerce_admin_meta_boxes.ajax_url, | |
data: data, | |
type: 'POST', | |
success: function( response ) { | |
var info = response; | |
if ( info ) { | |
$( 'input#_billing_first_name' ).val( info.billing_first_name ); | |
$( 'input#_billing_last_name' ).val( info.billing_last_name ); | |
$( 'input#_billing_company' ).val( info.billing_company ); | |
$( 'input#_billing_address_1' ).val( info.billing_address_1 ); | |
$( 'input#_billing_address_2' ).val( info.billing_address_2 ); | |
$( 'input#_billing_city' ).val( info.billing_city ); | |
$( 'input#_billing_postcode' ).val( info.billing_postcode ); | |
$( '#_billing_country' ).val( info.billing_country ); | |
$( 'input#_billing_state' ).val( info.billing_state ); | |
$( 'input#_billing_email' ).val( info.billing_email ); | |
$( 'input#_billing_phone' ).val( info.billing_phone ); | |
$( 'input#_billing_vat' ).val( info.billing_vat ); | |
$( 'input#_billing_ssn' ).val( info.billing_ssn ); | |
} | |
$( '.edit_address' ).unblock(); | |
} | |
}); | |
} | |
return false; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment