Skip to content

Instantly share code, notes, and snippets.

@dancameron
Created August 29, 2012 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dancameron/3515862 to your computer and use it in GitHub Desktop.
Save dancameron/3515862 to your computer and use it in GitHub Desktop.
Copy Billing into Shipping and cache original values.
gbs.ready = function($) {
var $copy_billing_option = $('#gb_shipping_copy_billing');
var $shipping_option_cache = {}; // cache options
$copy_billing_option.bind( 'change', function() {
// Loop over all gb_shipping options, unknowingly what is actually set because of customizations.
$('#gb-shipping [name^="gb_shipping_"]').each(function () {
if ( $( $copy_billing_option ).is(':checked') ) {
var $billing_name = this.name.replace('gb_shipping_', 'gb_billing_'); // Search for a matching field
$shipping_option_cache[this.name] = $(this).val(); // Cache the original option so it can be used later.
$( this ).val( $( '[name="' + $billing_name + '"]' ).val() ); // set the value
}
else {
$( this ).val( $shipping_option_cache[this.name] );
};
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment