/home/silvwabw/www/wp-content/themes/taxico-child/functions.php
<?php
if ( ! function_exists( 'taxico_child_enqueue_style' ) ) {
/**
* Load child theme style
*/
function taxico_child_style() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'parent-style' ) );
}
add_action( 'wp_enqueue_scripts', 'taxico_child_style' );
}
/**
* Your code goes below.
*/
function add_timepicker_js(){
wp_enqueue_script('js_lib',
'https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js',
array(),
null, true);
wp_enqueue_script('wicked_js',
'https://cdn.jsdelivr.net/npm/wickedpicker@0.4.3/dist/wickedpicker.min.js',
array(),
null,
true
);
wp_enqueue_style('wicked_css',
'https://cdn.jsdelivr.net/npm/wickedpicker@0.4.3/dist/wickedpicker.min.css',
array(),
null
);
wp_enqueue_script('custom-js', // Handle name
get_template_directory_uri() . '-child/timepicker.js', // Path to your JS file
array(), // Dependencies (like jQuery)
null, // Version (optional)
true // Load in footer
);
}
add_action( 'wp_enqueue_scripts', 'add_timepicker_js' );
function load_google_places_script() {
?>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDRPjDBsYw_PQ3BTv-Meh6vuFa2wpkdqmQ&libraries=places"></script>
<script>
function initGoogleAutocomplete() {
// Find the actual <input> inside the form group with class 'location-input'
const wrapper = document.querySelector('.location-input');
if (!wrapper) {
console.log('Location wrapper not found, retrying...');
return setTimeout(initGoogleAutocomplete, 500);
}
const input = wrapper.querySelector('input');
if (!input) {
console.log('Location input not found inside wrapper, retrying...');
return setTimeout(initGoogleAutocomplete, 500);
}
try {
new google.maps.places.Autocomplete(input, {
types: ['geocode', 'establishment']
});
console.log('Google Autocomplete initialized successfully.');
} catch (err) {
console.error('Failed to initialize Google Autocomplete:', err);
}
//for dropoff input
const wrapper1 = document.querySelector('.location-input1');
if (!wrapper1) {
console.log('Location wrapper1 not found, retrying...');
return setTimeout(initGoogleAutocomplete, 500);
}
const input1 = wrapper1.querySelector('input');
if (!input1) {
console.log('Location input not found inside wrapper1, retrying...');
return setTimeout(initGoogleAutocomplete, 500);
}
try {
new google.maps.places.Autocomplete(input1, {
types: ['geocode', 'establishment']
});
console.log('Google Autocomplete initialized successfully.');
} catch (err) {
console.error('Failed to initialize Google Autocomplete:', err);
}
}
document.addEventListener('DOMContentLoaded', function () {
// Wait a bit to ensure Gutenverse finishes rendering
setTimeout(initGoogleAutocomplete, 1000);
});
</script>
<?php
}
add_action('wp_footer', 'load_google_places_script');