Plugin Directory

Changeset 3248924


Ignore:
Timestamp:
03/01/2025 04:38:58 PM (13 months ago)
Author:
webv8
Message:

Version 1.5 Added New Block Style Checkout Page Compatibility

Location:
address-autosuggest-for-woocommerce
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • address-autosuggest-for-woocommerce/tags/1.4.1/readme.txt

    r3233617 r3248924  
     1=== Address AutoSuggest for WooCommerce ===
    12Contributors: webv8
    23Donate link: https://webv8.net/donate/
  • address-autosuggest-for-woocommerce/trunk/address-autosuggest-for-woocommerce.php

    r3233617 r3248924  
    44 * Plugin URI: https://webv8.net/address-autosuggest-for-woocommerce/
    55 * Description: Enable Google Places API on the checkout page to autocomplete WooCommerce address fields.
    6  * Version: 1.4.1
     6 * Version: 1.5
    77 * Author: Web V8
    88 * Author URI: https://webv8.net
     
    1818}
    1919
    20 define( 'ADDRESS_AUTOSUGGEST_FOR_WOOCOMMERCE_VERSION', '1.1' );
     20define( 'ADDRESS_AUTOSUGGEST_FOR_WOOCOMMERCE_VERSION', '1.5' );
    2121define( 'ADDRESS_AUTOSUGGEST_FOR_WOOCOMMERCE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
    2222define( 'ADDRESS_AUTOSUGGEST_FOR_WOOCOMMERCE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
     
    2727
    2828add_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(); });
     1document.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  
    11<?php
    22if ( ! defined( 'ABSPATH' ) ) {
    3     exit; // Exit if accessed directly
     3    exit;
    44}
     5
    56class Address_AutoSuggest {
    67    public static function init() {
     
    910
    1011    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 ) ) ) ) {
    1213            $api_key = get_option( ADDRESS_AUTOSUGGEST_FOR_WOOCOMMERCE_SETTINGS_OPTION, '' );
    1314            $selected_countries = get_option( 'address_autosuggest_countries', [] );
    1415            $plugin_url = plugin_dir_url( __FILE__ );
    1516
    16             // Enqueue your custom script with version
    1717            wp_enqueue_script(
    1818                'address-autosuggest',
    1919                $plugin_url . '../assets/js/address-autosuggest.js',
    2020                [ 'jquery' ],
    21                 filemtime( plugin_dir_path( __FILE__ ) . '../assets/js/address-autosuggest.js' ), // Version based on file modification time
     21                filemtime( plugin_dir_path( __FILE__ ) . '../assets/js/address-autosuggest.js' ),
    2222                true
    2323            );
    24 
    25             // Localize data for JavaScript
     24           
    2625            wp_localize_script( 'address-autosuggest', 'AddressAutoSuggestData', [
    2726                'selectedCountries' => $selected_countries,
    28                 'apiKey' => $api_key,
     27                'apiKey'            => $api_key,
    2928            ] );
    30 
    31             // Enqueue Google Maps API script with a fallback version
     29           
    3230            if ( ! empty( $api_key ) ) {
    3331                wp_enqueue_script(
     
    3533                    'https://maps.googleapis.com/maps/api/js?key=' . esc_attr( $api_key ) . '&libraries=places',
    3634                    [],
    37                     '1.0', // Use a fixed version since it's a third-party resource
     35                    '1.0',
    3836                    true
    3937                );
  • address-autosuggest-for-woocommerce/trunk/readme.txt

    r3233617 r3248924  
     1=== Address AutoSuggest for WooCommerce ===
    12Contributors: webv8
    23Donate link: https://webv8.net/donate/
    34Tags: WooCommerce, address, autocomplete, Google Places, checkout
    45Tested up to: 6.7
    5 Stable tag: 1.4.1
     6Stable tag: 1.5
    67License: GPLv2 or later
    78License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    5354== Changelog ==
    5455
     56= 1.5 =
     57* Added support for WooCommerce Block-Based Checkout.
     58* Improved script enqueue logic for better performance.
     59
    5560= 1.4.1 =
    5661* Added Step-by-Step Guide in the Settings Page.
     
    6671== Upgrade Notice ==
    6772
     73= 1.5 =
     74Support added for WooCommerce Block-Based Checkout. Ensure your checkout page works properly after updating.
     75
    6876= 1.4.1 =
    6977Added a Step-by-Step Guide in the Settings Page to improve user onboarding.
Note: See TracChangeset for help on using the changeset viewer.