Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xlplugins/ee758f3ae4ef5e9a096da3ab1dc6235e to your computer and use it in GitHub Desktop.
Save xlplugins/ee758f3ae4ef5e9a096da3ab1dc6235e to your computer and use it in GitHub Desktop.
show customer shipping or billing into checkout fields
add_filter( 'woocommerce_form_field_args', function ( $args, $key, $value ) {
$args['custom_attributes']['data-profile'] = $value;
return $args;
}, 20, 3 );
add_action( 'wp_footer', function () {
if ( ! is_user_logged_in() ) {
return;
}
?>
<script language="JavaScript">
(function ($) {
$(document.body).on('change', '#shipping_same_as_billing,.shipping_same_as_billing', function () {
setTimeout(() => {
$('.wfacp_divider_billing .wfacp-form-control[data-profile]').each(function () {
$(this).val($(this).data('profile'));
})
});
})
$(document.body).on('change', '#billing_same_as_shipping,.billing_same_as_shipping', function () {
setTimeout(() => {
$('.wfacp_divider_billing .wfacp-form-control[data-profile]').each(function () {
console.log($(this).data('profile'));
$(this).val($(this).data('profile'));
})
});
});
})(jQuery)
</script>
<?php
}, 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment