Created
August 29, 2012 17:26
-
-
Save dancameron/3515862 to your computer and use it in GitHub Desktop.
Copy Billing into Shipping and cache original values.
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
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