Last active
August 23, 2020 09:28
-
-
Save wpmudev-sls/2c2e171c6024b80ea44938a356da7fde to your computer and use it in GitHub Desktop.
[General] Fix Js Bug On ACF Address Autosuggest & Autocomplete
This file contains 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 | |
/** | |
* Plugin Name: [General] Fix Js Bug On ACF Address Autosuggest & Autocomplete | |
* Description: [General] Fix Js Bug On ACF Address Autosuggest & Autocomplete | |
* Author: Thobk @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
add_action( 'plugins_loaded', function(){ | |
if( function_exists('bb_acf_aa_footer_function') ){ | |
remove_action('admin_footer', 'bb_acf_aa_footer_function'); | |
remove_action('wp_footer', 'bb_acf_aa_footer_function'); | |
add_action( 'acf/enqueue_scripts',function(){ | |
add_action('admin_footer', 'wpmudev_bb_acf_aa_footer_function', 21); | |
add_action('wp_footer', 'wpmudev_bb_acf_aa_footer_function', 21); | |
}); | |
function wpmudev_bb_acf_aa_footer_function() { | |
$apikey = get_option( 'bb_google_api_key', '' ); | |
$bb_google_acf_aa_country = get_option( 'bb_google_acf_aa_country', '' ); | |
$bb_google_acf_aa_type = get_option( 'bb_google_acf_aa_type', '' ); | |
?> | |
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&key=<?php echo $apikey; ?>&libraries=places"></script> | |
<style> | |
.pac-container { | |
z-index:20000; position:absolute; | |
} | |
</style> | |
<script> | |
jQuery(document).ready(function($){ | |
$.each( $('.bb_acf_aa'), function (i, v){ | |
var country = '<?php echo $bb_google_acf_aa_country; ?>'; | |
var sugtype = '<?php echo $bb_google_acf_aa_type; ?>'; | |
var options = {}; | |
if(country!==''){ | |
options['componentRestrictions'] = {country: country}; | |
} | |
if(sugtype!==''){ | |
options['types']=[sugtype]; | |
} | |
var autocomplete = new google.maps.places.Autocomplete(v,options); | |
}); | |
// var acf = ''; | |
// acf.add_action('append', function( $el ){ | |
// var country = '<?php //echo $bb_google_acf_aa_country; ?>'; | |
// var sugtype = '<?php //echo $bb_google_acf_aa_type; ?>'; | |
// var options = {}; | |
// if(country!==''){ | |
// options['componentRestrictions'] = {country: country}; | |
// } | |
// if(sugtype!==''){ | |
// options['types']=[sugtype]; | |
// } | |
// var row = $el[0]; | |
// var input = $(row).find('.bb_acf_aa').attr('id'); | |
// var aut = new google.maps.places.Autocomplete(document.getElementById(input) ,options); | |
// }); | |
}); | |
</script> | |
<?php | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment