Skip to content

Instantly share code, notes, and snippets.

@dougkeeling
Created May 9, 2023 13:08
Show Gist options
  • Save dougkeeling/6eef1e13e421b4188c3fd75e58cdefd9 to your computer and use it in GitHub Desktop.
Save dougkeeling/6eef1e13e421b4188c3fd75e58cdefd9 to your computer and use it in GitHub Desktop.
[Copy Shipping/Billing Address] Copy addresses from billing to shipping in Gravity Forms #php #wordpress #javascript #gravityforms
// Then all you need to do is create a checkbox with the CSS class "fill-check," give the fields you want to fill from the class "fill-from," and give the fields you want to fill into the class "to-fill" (classes can be added under the "appearance" tab on forms). As long as the labels for the fields are the same, it should work.
//bind the click function
$(document).on('click', '.fill-check input', function() {
if($(this).is(':checked')) {
//put in the selectors we fill from
var fill_from = $('.fill-from, .fill-from .name_last, .fill-from .name_first, .fill-from .address_line_1, .fill-from .address_line_2, .fill-from .address_city, .fill-from .address_state, .fill-from .address_zip, .fill-from .address_country');
fill_from.each(function() {
//get the label
label = $(this).find('label').text();
//get the value
value = $(this).find('input').val();
//attempt to fill the new field with the value
to_fill = $('.to-fill label:contains("' + label + '")').siblings().find('input').val(value);
if(to_fill.length < 1) {
//this is so name fields will work
to_fill = $('.to-fill label:contains("' + label + '")').siblings('input').val(value);
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment