Changeset 3248924
- Timestamp:
- 03/01/2025 04:38:58 PM (13 months ago)
- Location:
- address-autosuggest-for-woocommerce
- Files:
-
- 9 edited
-
assets/banner-1544x500.png (modified) (previous)
-
assets/banner-772x250.png (modified) (previous)
-
assets/icon-128x128.png (modified) (previous)
-
assets/icon-256x256.png (modified) (previous)
-
tags/1.4.1/readme.txt (modified) (1 diff)
-
trunk/address-autosuggest-for-woocommerce.php (modified) (3 diffs)
-
trunk/assets/js/address-autosuggest.js (modified) (1 diff)
-
trunk/includes/class-address-autosuggest.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
address-autosuggest-for-woocommerce/tags/1.4.1/readme.txt
r3233617 r3248924 1 === Address AutoSuggest for WooCommerce === 1 2 Contributors: webv8 2 3 Donate link: https://webv8.net/donate/ -
address-autosuggest-for-woocommerce/trunk/address-autosuggest-for-woocommerce.php
r3233617 r3248924 4 4 * Plugin URI: https://webv8.net/address-autosuggest-for-woocommerce/ 5 5 * Description: Enable Google Places API on the checkout page to autocomplete WooCommerce address fields. 6 * Version: 1. 4.16 * Version: 1.5 7 7 * Author: Web V8 8 8 * Author URI: https://webv8.net … … 18 18 } 19 19 20 define( 'ADDRESS_AUTOSUGGEST_FOR_WOOCOMMERCE_VERSION', '1. 1' );20 define( 'ADDRESS_AUTOSUGGEST_FOR_WOOCOMMERCE_VERSION', '1.5' ); 21 21 define( 'ADDRESS_AUTOSUGGEST_FOR_WOOCOMMERCE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 22 22 define( 'ADDRESS_AUTOSUGGEST_FOR_WOOCOMMERCE_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); … … 27 27 28 28 add_action( 'plugins_loaded', [ 'Address_AutoSuggest', 'init' ] ); 29 -
address-autosuggest-for-woocommerce/trunk/assets/js/address-autosuggest.js
r3231295 r3248924 1 document.addEventListener( 'DOMContentLoaded', function () { function initializeAutoSuggest() { const addressField = document.getElementById('billing_address_1'); if (!addressField) { return; } const selectedCountries = AddressAutoSuggestData?.selectedCountries || []; const autocomplete = new google.maps.places.Autocomplete(addressField, { types: ['address'], componentRestrictions: { country: selectedCountries }, }); autocomplete.addListener('place_changed', function () { const place = autocomplete.getPlace(); if (!place || !place.address_components) { return; } const addressData = { street_number: '', route: '', locality: '', postal_town: '', postal_code: '', administrative_area_level_1: '', }; place.address_components.forEach((component) => { const types = component.types; if (types.includes('street_number')) { addressData.street_number = component.long_name || ''; } if (types.includes('route')) { addressData.route = component.long_name || ''; } if (types.includes('locality')) { addressData.locality = component.long_name || ''; } if (types.includes('postal_town')) { addressData.postal_town = component.long_name || ''; } if (types.includes('postal_code')) { addressData.postal_code = component.long_name || ''; } if (types.includes('administrative_area_level_1')) { addressData.administrative_area_level_1 = component.short_name || ''; } }); const address1Field = document.getElementById('billing_address_1'); const cityField = document.getElementById('billing_city'); const postcodeField = document.getElementById('billing_postcode'); const stateField = document.getElementById('billing_state'); const countryField = document.getElementById('billing_country'); if (address1Field) { address1Field.value = `${addressData.street_number} ${addressData.route}`.trim(); } if (cityField) { cityField.value = addressData.locality || addressData.postal_town || ''; cityField.dispatchEvent(new Event('change')); } if (postcodeField) { postcodeField.value = addressData.postal_code || ''; postcodeField.dispatchEvent(new Event('change')); } if (stateField) { stateField.value = addressData.administrative_area_level_1 || ''; stateField.dispatchEvent(new Event('change')); } const checkoutForm = document.querySelector('form.checkout'); if (checkoutForm) { jQuery(document.body).trigger('update_checkout'); } }); } function waitForGoogleMapsAPI() { if (typeof google !== 'undefined' && typeof google.maps !== 'undefined') { initializeAutoSuggest(); } else { setTimeout(waitForGoogleMapsAPI, 500); } } waitForGoogleMapsAPI();});1 document.addEventListener("DOMContentLoaded",function(){function e(e,t){return document.getElementById(e+"-"+t)||document.getElementById(e+"_"+t)}function t(e,t){return Boolean(document.getElementById(e+"-"+t))}function n(n,o,a){var i=e(n,o);i&&(t(n,o)?function e(t,n){if(t){try{var o=Object.getPrototypeOf(t);Object.getOwnPropertyDescriptor(o,"value").set.call(t,n)}catch(a){t.value=n}t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0}))}}(i,a):(i.value=a,i.dispatchEvent(new Event("change"))))}function o(e,t){n(e,"address_1",(t.street_number+" "+t.route).trim()),n(e,"city",t.locality||t.postal_town||""),n(e,"postcode",t.postal_code||""),n(e,"state",t.administrative_area_level_1||"")}function a(n){var a,i,r,s="address_1";a=n,i=function(e){var a,i,r,s;a=n,i=e,r=AddressAutoSuggestData&&AddressAutoSuggestData.selectedCountries||[],(s=new google.maps.places.Autocomplete(i,{types:["address"],componentRestrictions:{country:r}})).addListener("place_changed",function(){var e=s.getPlace();if(e&&e.address_components){var n,r,c=(n=e,r={street_number:"",route:"",locality:"",postal_town:"",postal_code:"",administrative_area_level_1:""},n.address_components.forEach(function(e){var t=e.types;-1!==t.indexOf("street_number")&&(r.street_number=e.long_name||""),-1!==t.indexOf("route")&&(r.route=e.long_name||""),-1!==t.indexOf("locality")&&(r.locality=e.long_name||""),-1!==t.indexOf("postal_town")&&(r.postal_town=e.long_name||""),-1!==t.indexOf("postal_code")&&(r.postal_code=e.long_name||""),-1!==t.indexOf("administrative_area_level_1")&&(r.administrative_area_level_1=e.short_name||"")}),r);t("billing","address_1")?(o("billing",c),o("shipping",c)):o(a,c),t(a,"address_1")&&(i.blur(),setTimeout(function(){document.body.focus()},100),google.maps.event.clearInstanceListeners(s),setTimeout(function(){document.querySelectorAll(".pac-container").forEach(function(e){e.remove()})},200)),document.querySelector("form.checkout")&&jQuery(document.body).trigger("update_checkout")}})},r=e(a,s),r?i(r):new MutationObserver(function(t,n){var o=e(a,s);o&&(n.disconnect(),i(o))}).observe(document.body,{childList:!0,subtree:!0})}!function e(t){"undefined"!=typeof google&&void 0!==google.maps?t():setTimeout(function(){e(t)},500)}(function(){a("billing"),a("shipping")})}); -
address-autosuggest-for-woocommerce/trunk/includes/class-address-autosuggest.php
r3228771 r3248924 1 1 <?php 2 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; // Exit if accessed directly3 exit; 4 4 } 5 5 6 class Address_AutoSuggest { 6 7 public static function init() { … … 9 10 10 11 public static function enqueue_scripts() { 11 if ( class_exists( 'WooCommerce' ) && is_checkout() ) {12 if ( class_exists( 'WooCommerce' ) && ( is_checkout() || ( is_singular() && has_block( 'woocommerce/checkout', get_post()->post_content ) ) ) ) { 12 13 $api_key = get_option( ADDRESS_AUTOSUGGEST_FOR_WOOCOMMERCE_SETTINGS_OPTION, '' ); 13 14 $selected_countries = get_option( 'address_autosuggest_countries', [] ); 14 15 $plugin_url = plugin_dir_url( __FILE__ ); 15 16 16 // Enqueue your custom script with version17 17 wp_enqueue_script( 18 18 'address-autosuggest', 19 19 $plugin_url . '../assets/js/address-autosuggest.js', 20 20 [ 'jquery' ], 21 filemtime( plugin_dir_path( __FILE__ ) . '../assets/js/address-autosuggest.js' ), // Version based on file modification time21 filemtime( plugin_dir_path( __FILE__ ) . '../assets/js/address-autosuggest.js' ), 22 22 true 23 23 ); 24 25 // Localize data for JavaScript 24 26 25 wp_localize_script( 'address-autosuggest', 'AddressAutoSuggestData', [ 27 26 'selectedCountries' => $selected_countries, 28 'apiKey' => $api_key,27 'apiKey' => $api_key, 29 28 ] ); 30 31 // Enqueue Google Maps API script with a fallback version 29 32 30 if ( ! empty( $api_key ) ) { 33 31 wp_enqueue_script( … … 35 33 'https://maps.googleapis.com/maps/api/js?key=' . esc_attr( $api_key ) . '&libraries=places', 36 34 [], 37 '1.0', // Use a fixed version since it's a third-party resource35 '1.0', 38 36 true 39 37 ); -
address-autosuggest-for-woocommerce/trunk/readme.txt
r3233617 r3248924 1 === Address AutoSuggest for WooCommerce === 1 2 Contributors: webv8 2 3 Donate link: https://webv8.net/donate/ 3 4 Tags: WooCommerce, address, autocomplete, Google Places, checkout 4 5 Tested up to: 6.7 5 Stable tag: 1. 4.16 Stable tag: 1.5 6 7 License: GPLv2 or later 7 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 53 54 == Changelog == 54 55 56 = 1.5 = 57 * Added support for WooCommerce Block-Based Checkout. 58 * Improved script enqueue logic for better performance. 59 55 60 = 1.4.1 = 56 61 * Added Step-by-Step Guide in the Settings Page. … … 66 71 == Upgrade Notice == 67 72 73 = 1.5 = 74 Support added for WooCommerce Block-Based Checkout. Ensure your checkout page works properly after updating. 75 68 76 = 1.4.1 = 69 77 Added a Step-by-Step Guide in the Settings Page to improve user onboarding.
Note: See TracChangeset
for help on using the changeset viewer.