Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save xlplugins/465bfbdfed859b954aec0a78c8d56831 to your computer and use it in GitHub Desktop.

Select an option

Save xlplugins/465bfbdfed859b954aec0a78c8d56831 to your computer and use it in GitHub Desktop.
shipping value not showing
add_action(
'wp_enqueue_scripts',
static function () {
if ( ! wp_script_is( 'wfacp_checkout_js', 'registered' ) ) {
return;
}
wp_register_script( 'wfacp-restore-prefilled-names', false, array( 'jquery', 'wfacp_checkout_js' ), '1.3', true );
wp_enqueue_script( 'wfacp-restore-prefilled-names' );
$js = <<<'JS'
(function ($) {
var bad = /hidden|checkbox|radio|submit|button|file|image/i;
function sep($e) {
var t = $e.prop('type');
return (t === 'radio' && $e.val() === 'option_2') || (t === 'checkbox' && $e.is(':checked'));
}
function run(prefix) {
$('#wfacp_checkout_form').find('input,textarea,select').each(function () {
var e = this,
n = e.name || '',
d,
$e = $(e);
if (n.indexOf(prefix) !== 0 || /same_as/.test(n)) {
return;
}
if (e.tagName === 'SELECT') {
d = e.defaultValue;
if (!d || $e.val() !== '') {
return;
}
$e.val(d).trigger('change');
return;
}
if (bad.test(e.type || '')) {
return;
}
d = e.defaultValue;
if (!d || $e.val() !== '') {
return;
}
$e.val(d).trigger('input').trigger('change').closest('p.form-row,.wfacp-form-control-wrapper').addClass('wfacp-anim-wrap');
try {
var iti = window.intlTelInput && intlTelInput.getInstance && intlTelInput.getInstance(e);
if (iti && iti.setNumber) {
iti.setNumber(d);
}
} catch (x) {}
});
}
function twice(p) {
run(p);
setTimeout(function () {
run(p);
}, 220);
}
$(document.body)
.on('change', '#shipping_same_as_billing,.shipping_same_as_billing', function () {
if (sep($(this))) {
setTimeout(function () {
twice('shipping_');
}, 0);
}
})
.on('change', '#billing_same_as_shipping,.billing_same_as_shipping', function () {
if (sep($(this))) {
setTimeout(function () {
twice('billing_');
}, 0);
}
});
})(jQuery);
JS;
wp_add_inline_script( 'wfacp-restore-prefilled-names', $js );
},
999
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment