Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tamarazuk/c39178e698fecea66d59 to your computer and use it in GitHub Desktop.
Save tamarazuk/c39178e698fecea66d59 to your computer and use it in GitHub Desktop.
WooCommerce Address Validation SmartyStreets badge fix
<?php
function wc_address_validation_smartystreets_badge_fix() {
wc_enqueue_js( '
$( "body" ).on( "wc_address_validation_fields_mapped", function() {
$.each( [ "billing", "shipping" ], function( index, addressType ) {
var fields = $( "#" + addressType + "_address_1, #" + addressType + "_address_2, #" + addressType + "_city, #" + addressType + "_state, #" + addressType + "_postcode, #" + addressType + "_country" );
fields.on( "visibility", function() {
var $field = $( this );
var $smartyBadge = $( "a.smarty-addr-" + addressType );
setInterval( function() {
if ( $field.is( ":visible" ) && $smartyBadge.is( ":hidden" ) ) {
// show the verify address button
$smartyBadge.parent( "div" ).show();
$( window ).resize(); // trigger the re-position of .smarty-autocomplete
}
if ( $field.is( ":hidden" ) && $smartyBadge.is( ":visible" ) ) {
// hide the verify address button
$smartyBadge.parent( "div" ).hide();
$( window ).resize(); // trigger the re-position of .smarty-autocomplete
}
}, 300 );
}).trigger( "visibility" );
} );
} );
' );
}
add_action( 'wp_enqueue_scripts', 'wc_address_validation_smartystreets_badge_fix' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment