Last active
August 29, 2015 14:12
-
-
Save tamarazuk/c39178e698fecea66d59 to your computer and use it in GitHub Desktop.
WooCommerce Address Validation SmartyStreets badge fix
This file contains hidden or 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
<?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