diff --git a/assets/admin/js/lpac-admin.js b/assets/admin/js/lpac-admin.js index 1dd8c13..ec9d6ea 100644 --- a/assets/admin/js/lpac-admin.js +++ b/assets/admin/js/lpac-admin.js @@ -68,6 +68,24 @@ } // hideSaveButtonOnExportTab(); + /** + * Check if the Google Maps API Key has been entered on the settings page. + */ + function checkAPIKeyPresence() { + const field = $("#lpac_google_maps_api_key"); + + if (field.length < 1) { + return; + } + + if (field.val().length > 10) { + return; + } + + field.css("box-shadow", "1px 1px 10px 5px red"); + } + checkAPIKeyPresence(); + /** * Toggle AutoDetect customer location option on Generals Settings page. */ diff --git a/assets/admin/js/repeater-setup.js b/assets/admin/js/repeater-setup.js index 8adf63f..93625e8 100644 --- a/assets/admin/js/repeater-setup.js +++ b/assets/admin/js/repeater-setup.js @@ -59,7 +59,7 @@ // to the server, etc. If a hide callback is not given the item // will be deleted. hide: function (deleteElement) { - if (confirm("Are you sure you want to delete this element?")) { + if (confirm("Are you sure you want to delete this entry?")) { $(this).slideUp(deleteElement); } }, diff --git a/assets/public/js/maps/checkout-page-map.js b/assets/public/js/maps/checkout-page-map.js index 7f62f55..bc8fcf2 100644 --- a/assets/public/js/maps/checkout-page-map.js +++ b/assets/public/js/maps/checkout-page-map.js @@ -749,13 +749,16 @@ function lpacSetLastOrderLocationCords() { */ function lpacSetLastOrderForAutocompleteWithoutMap() { const hideMapForAutocomplete = mapOptions.lpac_places_autocomplete_hide_map; + const enablePlacesAutoComplete = mapOptions.lpac_enable_places_autocomplete; - if (!hideMapForAutocomplete) { + if (enablePlacesAutoComplete === false && hideMapForAutocomplete === false) { return; } const field = document.querySelector("#lpac_order__origin_store_field"); - field.classList.remove("hidden"); + if (field) { + field.classList.remove("hidden"); + } lpacSetLastOrderLocationCords(); } @@ -1012,8 +1015,13 @@ addPlacesAutoComplete(); */ const hideMapForAutocomplete = mapOptions.lpac_places_autocomplete_hide_map; + const enablePlacesAutoComplete = + mapOptions.lpac_enable_places_autocomplete; - if (!hideMapForAutocomplete) { + if ( + enablePlacesAutoComplete === false && + hideMapForAutocomplete === false + ) { return; } @@ -1079,9 +1087,10 @@ addPlacesAutoComplete(); * Weird bug with fluid checkout causing field to disappear if we try to move it too early. */ if (checkoutProvider === "fluidcheckout") { - setTimeout(() => { + $(document.body).on("updated_checkout", function () { + let field = $("#lpac_order__origin_store_field"); field.insertAfter("#shipping_address_1_field"); - }, "1500"); + }); } } moveStoreSelector(); @@ -1094,7 +1103,13 @@ addPlacesAutoComplete(); // In those cases we have no need to wait until a location is found from the map to show the field. const hideMapForAutocomplete = mapOptions.lpac_places_autocomplete_hide_map; - if (hideMapForAutocomplete) { + const enablePlacesAutoComplete = + mapOptions.lpac_enable_places_autocomplete; + + if ( + enablePlacesAutoComplete === true && + hideMapForAutocomplete === true + ) { return; } diff --git a/class-lpac-uninstall.php b/class-lpac-uninstall.php index 9ed22a5..ac7445b 100644 --- a/class-lpac-uninstall.php +++ b/class-lpac-uninstall.php @@ -108,6 +108,7 @@ public static function remove_plugin_settings() { 'lpac_export_date_to', 'lpac_places_autocomplete_country_restrictions', 'lpac_places_autocomplete_type', + 'lpac_enable_shipping_cost_by_distance_feature', 'lpac_distance_matrix_api_key', 'lpac_distance_matrix_store_origin_cords', 'lpac_distance_matrix_cost_per_unit', @@ -139,6 +140,9 @@ public static function remove_plugin_settings() { 'lpac_enable_cost_by_store_location', 'lpac_cost_by_store_distance_delivery_prices', 'lpac_cost_by_store_location_delivery_prices', + 'lpac_cost_by_store_location_shipping_methods', + 'lpac_migrated__add_address_to_store_locations', + 'lpac_show_selected_store_in_emails', ); foreach ( $option_keys as $key ) { diff --git a/includes/Bootstrap/Main.php b/includes/Bootstrap/Main.php index b970161..9cf55b2 100644 --- a/includes/Bootstrap/Main.php +++ b/includes/Bootstrap/Main.php @@ -27,6 +27,9 @@ */ namespace Lpac\Bootstrap; +if ( !defined( 'WPINC' ) ) { + die; +} use Lpac\Bootstrap\Loader ; use Lpac\Bootstrap\I18n ; use Lpac\Bootstrap\Admin_Enqueues ; @@ -42,6 +45,7 @@ use Lpac\Views\Frontend as Frontend_Display ; use Lpac\Compatibility\WooFunnels\WooFunnels ; use Lpac\Models\Location_Details ; +use Lpac\Models\Migrations ; use Lpac\Controllers\API\Order as API_Order ; /** * Class Main. @@ -152,6 +156,11 @@ private function define_admin_hooks() $admin_settings_controller = new Admin_Settings_Controller(); $controller_map_visibility = new Map_Visibility_Controller(); $api_orders = new API_Order(); + $migrations = new Migrations(); + /** + * Plugin settings migrations + */ + $this->loader->add_action( 'admin_init', $migrations, 'add_address_field_to_store_locations' ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); // Notices @@ -200,21 +209,12 @@ private function define_admin_hooks() 10, 3 ); - /** - * Migrate old way of saving store locations to new array structure. Added @1.6.0 - */ - $this->loader->add_action( - 'admin_init', - $admin_settings_controller, - 'migrate_old_store_locations', - 10, - 3 - ); /* Custom elements created for WooCommerce settings */ $this->loader->add_action( 'woocommerce_admin_field_button', $plugin_admin_view, 'create_custom_wc_settings_button' ); $this->loader->add_action( 'woocommerce_admin_field_hr', $plugin_admin_view, 'create_custom_wc_settings_hr' ); $this->loader->add_action( 'woocommerce_admin_field_div', $plugin_admin_view, 'create_custom_wc_settings_div' ); $this->loader->add_action( 'woocommerce_admin_field_repeater', $plugin_admin_view, 'create_custom_wc_settings_repeater' ); + $this->loader->add_action( 'woocommerce_admin_field_info_text', $plugin_admin_view, 'create_custom_wc_settings_info_text' ); $this->loader->add_filter( 'plugin_action_links', $this, @@ -338,8 +338,18 @@ private function define_public_hooks() 2 ); } + /** + * Validate that a customer has selected a store location from the drop down selector. + */ + $this->loader->add_action( + 'woocommerce_after_checkout_validation', + $controller_checkout_page, + 'validate_store_location_selector_dropdown', + 10, + 2 + ); /* - * Display map button link or qr code link in email. + * Display map button link, static map or qr code link in order emails email. */ $enable_map_link_in_email = get_option( 'lpac_enable_delivery_map_link_in_email' ); @@ -355,6 +365,16 @@ private function define_public_hooks() ); } + /** + * Add selected store location to order emails. + */ + $this->loader->add_action( + 'woocommerce_email_customer_details', + $controller_emails, + 'add_store_location_to_email', + 20, + 4 + ); /* * Adds a notice for admin to checkout page */ diff --git a/includes/Compatibility/Checkout_Provider.php b/includes/Compatibility/Checkout_Provider.php index 24c612f..7475df9 100644 --- a/includes/Compatibility/Checkout_Provider.php +++ b/includes/Compatibility/Checkout_Provider.php @@ -42,6 +42,10 @@ public function get_checkout_provider() { $provider = 'fluidcheckout'; } + if ( defined( 'CFW_NAME' ) ) { + $provider = 'checkoutwc'; + } + if ( class_exists( 'Orderable_Pro', false ) ) { $settings = get_option( 'orderable_settings', array() ); $enable_custom_checkout = $settings['checkout_general_override_checkout'] ?? ''; diff --git a/includes/Controllers/Admin_Settings_Controller.php b/includes/Controllers/Admin_Settings_Controller.php index dea44d3..6d023a5 100644 --- a/includes/Controllers/Admin_Settings_Controller.php +++ b/includes/Controllers/Admin_Settings_Controller.php @@ -87,40 +87,4 @@ public function generate_store_id( array $values, array $option, array $raw_valu return $values; } - /** - * Migrate Store Locations from the old settings array to the new settings array. - * @return void - */ - public function migrate_old_store_locations() : void { - - $installed_at_version = LPAC_INSTALLED_AT_VERSION; - $migrated = get_option( 'lpac_migrated_store_locations' ); - - // Only perform this migration prior to v1.6.0 when we had the old method of adding store locations. - if ( $installed_at_version >= '1.6.0' || ! empty( $migrated ) ) { - return; - } - - $location_coordinates = get_option( 'lpac_store_locations_cords', array() ); - $location_names = get_option( 'lpac_store_locations_labels', array() ); - $location_icons = get_option( 'lpac_store_locations_icons', array() ); - - $location_coordinates_array = explode( '|', $location_coordinates ); - $location_names_array = explode( '|', $location_names ); - $location_icons_array = explode( '|', $location_icons ); - - $new_array_structure = array(); - - foreach ( $location_coordinates_array as $key => $cords ) { - $new_array_structure[] = array( - 'store_location_id' => sanitize_text_field( 'store_location_' . $key ), - 'store_name_text' => sanitize_text_field( $location_names_array[ $key ] ?? 'Branch Name' ), - 'store_cords_text' => sanitize_text_field( $cords ), - 'store_icon_text' => sanitize_text_field( $location_icons_array[ $key ] ?? '' ), - ); - } - - update_option( 'lpac_store_locations', $new_array_structure ); - update_option( 'lpac_migrated_store_locations', true ); - } } diff --git a/includes/Controllers/Checkout_Page_Controller.php b/includes/Controllers/Checkout_Page_Controller.php index 40dddc5..efc2204 100644 --- a/includes/Controllers/Checkout_Page_Controller.php +++ b/includes/Controllers/Checkout_Page_Controller.php @@ -138,10 +138,41 @@ public function get_last_order_location() { * * @since 1.5.7 * @since 1.6.0 use new store locations array + * @see setup_global_js_vars() * @return array */ public function get_store_locations() { return get_option( 'lpac_store_locations', array() ); } + /** + * Check if the origin store dropdown has a selected value for Store location selector feature in Shipping Locations settings. + * + * @since 1.6.0 + * @param array $fields The fields array. + * @param object $errors The errors object. + * + * @return void + */ + public function validate_store_location_selector_dropdown( array $fields, object $errors ) : void { + + $enable_store_location_selector = get_option( 'lpac_enable_store_location_selector' ); + $enable_store_location_selector = filter_var( $enable_store_location_selector, FILTER_VALIDATE_BOOL ); + + if ( empty( $enable_store_location_selector ) ) { + return; + } + + $origin_store = $_POST['lpac_order__origin_store'] ?? ''; + + $error_msg = '' . __( 'Please select the store location you would like to order from.', 'map-location-picker-at-checkout-for-woocommerce' ) . ''; + + $error_msg = apply_filters( 'lpac_checkout_empty_origin_store_msg', $error_msg ); + + if ( empty( $origin_store ) ) { + $errors->add( 'validation', $error_msg ); + } + + } + } diff --git a/includes/Controllers/Emails_Controller.php b/includes/Controllers/Emails_Controller.php index 23194cf..b2218bd 100644 --- a/includes/Controllers/Emails_Controller.php +++ b/includes/Controllers/Emails_Controller.php @@ -13,7 +13,6 @@ namespace Lpac\Controllers; -use Lpac\Helpers\Functions as Functions_Helper; use Lpac\Helpers\QR_Code_Generator; use Lpac\Traits\Upload_Folders; @@ -28,10 +27,14 @@ class Emails_Controller { /** * Outputs a Button or QR Code inside order emails. - * + * @param object $order + * @param bool $sent_to_admin + * @param bool $plain_text + * @param object $email * @since 1.1.0 + * @return void */ - public function add_delivery_location_link_to_email( $order, $sent_to_admin, $plain_text, $email ) { + public function add_delivery_location_link_to_email( object $order, bool $sent_to_admin, bool $plain_text, object $email ) { $allowed_emails = get_option( 'lpac_email_delivery_map_emails', array() ); @@ -183,4 +186,57 @@ private function create_delivery_location_static_map( $order_id, $map_link, $lat } + /** + * Adds store location to order email + * + * @param object $order + * @param bool $sent_to_admin + * @param bool $plain_text + * @param object $email + * @since 1.6.2 + * @return void + */ + public function add_store_location_to_email( object $order, bool $sent_to_admin, bool $plain_text, object $email ): void { + + $show_in_emails = get_option( 'lpac_show_selected_store_in_emails', 'yes' ); + + if ( $show_in_emails !== 'yes' ) { + return; + } + + $label = get_option( 'lpac_store_select_label' ) ?: esc_html( 'Deliver from', 'map-location-picker-at-checkout-for-woocommerce' ); + $label = rtrim( $label, ':' ); + $store_origin_name = get_post_meta( $order->get_id(), '_lpac_order__origin_store_name', true ); + + if ( empty( $store_origin_name ) ) { + return; + } + + $store_locations = get_option( 'lpac_store_locations', array() ); + $address = ''; + + if ( empty( $store_locations ) ) { + return; + } + + $store_names = array_column( $store_locations, 'store_name_text' ); + $key = array_search( $store_origin_name, $store_names ); + + if ( $key !== false ) { + $address = $store_locations[ $key ]['store_address_text'] ?? ''; + $cords = $store_locations[ $key ]['store_cords_text'] ?? ''; + } + + $link = ( ! empty( $cords ) ) ? "https://www.google.com/maps/search/?api=1&query=$cords" : '#'; + + $markup = "
+ $label:
+
+ $store_origin_name
+ $address
+
+
$text
+Location Picker at Checkout: diff --git a/lpac.php b/lpac.php index 02e9ce6..2f16770 100644 --- a/lpac.php +++ b/lpac.php @@ -1,12 +1,6 @@ false, 'has_paid_plans' => true, 'menu' => array( - 'first-path' => 'admin.php?page=wc-settings&tab=lpac_settings', + 'first-path' => ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ? 'admin.php?page=wc-settings&tab=lpac_settings' : '' ), ), 'is_live' => true, ) ); diff --git a/readme.txt b/readme.txt index 3209288..9b42fe0 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: woocommerce, location picker, checkout map, geolocation, google map, map, Requires at least: 5.5 Requires PHP: 7.3 Tested up to: 6.1 -Stable tag: 1.5.7 +Stable tag: 1.6.2 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -209,6 +209,20 @@ Post it on the [support forum](https://wordpress.org/support/plugin/map-location == Upgrade Notice == == Changelog == += 1.6.2 = +* [New] Option to show selected store location in order emails. +* [New] New address field when creating Store Locations. +* [Fix] JS error when Store Location selector is not present on checkout page. +* [Fix] Store Location selector was always being moved below shipping address even when map was being shown on checkout. +* [Fix] Store Location validation was not being enforced in the free version of the plugin. +* [Fix] Default Store Location selector would not display on checkout page unless "Cost by Store Distance" feature was explicitly disabled. +* [Fix] Prevent plugin from trying to redirect to its settings if WooCommerce is not active. +* [Compatibility] Support for CheckoutWC - WooCommerce custom checkout plugin. + + += 1.6.1 = +* [Fix] Migration error for old store location settings to new store location feature. + = 1.6.0 = * [New PRO] Cost by Store Distance - Set order shipping price based on the customer's distance relative to your store location. * [New PRO] Cost by Store Location - Set order shipping price based on the store that the customer selects at checkout.