diff --git a/.distignore b/.distignore
index 115d7d9..daa78c4 100644
--- a/.distignore
+++ b/.distignore
@@ -1,15 +1,23 @@
composer.json
composer.lock
-todo.txt
-artifact
-dist
-bin
+package.json
+package-lock.json
+node_modules
+.vscode
+.parcel-cache
.git
.DS_Store
.distignore
.distignore-github-lite
.gitignore
+todo.txt
+artifact
+dist
+bin
phpcs.xml
lpac.zip
logs
-.vscode
\ No newline at end of file
+assets/public/js/maps/*.js
+assets/pro/public/js/maps/*.js
+assets/public/js/maps/build/*.map
+assets/pro/public/js/maps/build/*.map
\ No newline at end of file
diff --git a/.distignore-github-lite b/.distignore-github-lite
index 7d9cb39..1ce736b 100644
--- a/.distignore-github-lite
+++ b/.distignore-github-lite
@@ -5,4 +5,7 @@ dist
.DS_Store
lpac.zip
logs
-.vscode
\ No newline at end of file
+.vscode
+.parcel-cache
+node_modules
+assets/public/js/maps/build
diff --git a/.gitignore b/.gitignore
index 2464078..e76d912 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,8 @@ dist
artifact
lpac.zip
logs
-.vscode
\ No newline at end of file
+.vscode
+node_modules
+.parcel-cache
+assets/public/js/maps/build/
+assets/pro/public/js/maps/build/
\ No newline at end of file
diff --git a/assets/admin/css/lpac-admin.css b/assets/admin/css/lpac-admin.css
new file mode 100644
index 0000000..12ea358
--- /dev/null
+++ b/assets/admin/css/lpac-admin.css
@@ -0,0 +1,10 @@
+/**
+ * All of the CSS for your admin-specific functionality should be
+ * included in this file.
+ */
+ .post-type-shop_order .lpac-map .gm-style-iw-d p{
+ font-size: 1.2em;
+ font-weight: 800;
+ margin: 5px;
+ text-align: center;
+ }
\ No newline at end of file
diff --git a/includes/admin/js/lpac-admin.js b/assets/admin/js/lpac-admin.js
similarity index 100%
rename from includes/admin/js/lpac-admin.js
rename to assets/admin/js/lpac-admin.js
diff --git a/assets/admin/js/order-map.js b/assets/admin/js/order-map.js
new file mode 100644
index 0000000..24eb9ed
--- /dev/null
+++ b/assets/admin/js/order-map.js
@@ -0,0 +1,49 @@
+var map_id = '';
+
+if (typeof lpac_pro_js !== 'undefined') {
+ map_id = lpac_pro_js.map_id;
+}
+
+function lpacSetupShopOrderMap() {
+
+ /**
+ * This variable is defined in lpac_output_custom_order_details_metabox().
+ *
+ * It does not exist when in cases where lat and long might not be present for an order.
+ */
+ if (typeof (locationDetails) === 'undefined' || locationDetails === null) {
+ return;
+ }
+
+ const map = new google.maps.Map(
+ document.querySelector(".lpac-map"),
+ {
+ center: { lat: locationDetails.latitude, lng: locationDetails.longitude },
+ zoom: 16,
+ streetViewControl: false,
+ clickableIcons: false,
+ backgroundColor: '#eee', //loading background color
+ mapId: map_id,
+ }
+ );
+
+ const latlng = {
+ lat: locationDetails.latitude,
+ lng: locationDetails.longitude,
+ };
+
+ const marker = new google.maps.Marker(
+ {
+ position: latlng,
+ map: map,
+ cursor: 'default'
+ }
+ );
+
+ const infowindow = new google.maps.InfoWindow();
+ infowindow.setContent(`
${locationDetails.shipping_address_1}
${locationDetails.shipping_address_2}
`);
+ infowindow.open(map, marker);
+
+}
+
+lpacSetupShopOrderMap();
\ No newline at end of file
diff --git a/assets/public/css/lpac-public.css b/assets/public/css/lpac-public.css
new file mode 100644
index 0000000..f025f4b
--- /dev/null
+++ b/assets/public/css/lpac-public.css
@@ -0,0 +1,58 @@
+/**
+ * All of the CSS for your public-facing functionality should be
+ * included in this file.
+ */
+
+ .lpac-map{
+ height: 400px;
+ /* width: 100%; */
+ }
+
+ #lpac-find-location-btn{
+ margin: 20px 0;
+ }
+
+ .hidden{
+ display: none;
+ }
+
+ #lpac-map-instructions{
+ font-size: 12px;
+ margin: 10px;
+ text-align: center;
+ }
+
+ #lpac-find-location-btn-wrapper{
+ display: flex;
+ justify-content: center;
+ }
+
+ #lpac-saved-addresses{
+ text-align: center;
+ }
+
+ .lpac-map-controls #lpac-saved-addresses{
+ margin: 20px 0;
+ }
+
+ .lpac-map-controls #lpac-saved-addresses ul{
+ list-style-type: none;
+ padding: 0;
+ }
+
+ .lpac-map-controls #lpac-saved-addresses ul li{
+ display: inline-block;
+ margin: 10px 10px 0 0;
+ }
+
+ /* Google maps info window */
+ .woocommerce-page .lpac-map .gm-style-iw-d p{
+ font-size: 1.2em;
+ margin-bottom: 0;
+
+ }
+ .woocommerce-view-order .lpac-map .gm-style-iw-d p, .woocommerce-order-received .lpac-map .gm-style-iw-d p{
+ font-weight: 800;
+ text-align: center;
+ }
+
diff --git a/includes/admin/index.php b/assets/public/index.php
similarity index 100%
rename from includes/admin/index.php
rename to assets/public/index.php
diff --git a/includes/public/js/lpac-public.js b/assets/public/js/lpac-public.js
similarity index 56%
rename from includes/public/js/lpac-public.js
rename to assets/public/js/lpac-public.js
index ea4b4ec..3eda347 100644
--- a/includes/public/js/lpac-public.js
+++ b/assets/public/js/lpac-public.js
@@ -33,35 +33,6 @@
function(){
- var map_div = document.querySelector( '#lpac-map-container' );
- var map_shown = document.querySelector( '#lpac_is_map_shown' );
- var map_present = true;
- var map_visibility = '';
-
- if( typeof( map_shown ) === 'undefined' || map_shown === null ){
- console.log('LPAC: map_shown object not present, skipping...');
- return;
- }
-
- /**
- * Detect if map is present and the display property
- */
- if( typeof( map_div ) === 'undefined' || map_div === null ){
- map_present = false;
- }else{
- map_visibility = map_div.style.display;
- }
-
- if ( map_present === false || map_visibility === 'none' ) {
-
- if ( map_shown ) {
- map_shown.value = 0
- }
-
- } else {
- map_shown.value = 1
- }
-
}
);
diff --git a/assets/public/js/maps/base-map.js b/assets/public/js/maps/base-map.js
new file mode 100644
index 0000000..5a7cefd
--- /dev/null
+++ b/assets/public/js/maps/base-map.js
@@ -0,0 +1,45 @@
+let map_id = '';
+
+if (typeof lpac_pro_js !== 'undefined') {
+ map_id = lpac_pro_js.map_id;
+}
+
+/**
+ * Global map_options variable is set in Lpac\Views\Frontend::lpac_expose_map_settings_js
+ */
+if (typeof (map_options) !== 'undefined' && map_options !== null) {
+
+ /**
+ *
+ */
+ const map = new google.maps.Map(
+ document.querySelector(".lpac-map"),
+ {
+ center: { lat: map_options.lpac_map_default_latitude, lng: map_options.lpac_map_default_longitude },
+ zoom: map_options.lpac_map_zoom_level,
+ streetViewControl: false,
+ clickableIcons: map_options.lpac_map_clickable_icons,
+ backgroundColor: map_options.lpac_map_background_color, //loading background color
+ mapId: map_id,
+ }
+ );
+
+ /* Globally scoped so that only one marker can be added to map. */
+ const marker = new google.maps.Marker(
+ {
+ draggable: true,
+ map: map,
+ }
+ );
+
+ /* Globally scoped so that only one info window can be added to map. */
+ const infowindow = new google.maps.InfoWindow();
+
+ /* We need to set these variables to the window object or else parcel will break our script when transpiling */
+ window.lpac_map = map;
+ window.lpac_marker = marker;
+ window.lpac_infowindow = infowindow;
+
+} else {
+ console.log('LPAC: map_options object not present, skipping...')
+}
diff --git a/assets/public/js/maps/checkout-page-map.js b/assets/public/js/maps/checkout-page-map.js
new file mode 100644
index 0000000..3bd9f21
--- /dev/null
+++ b/assets/public/js/maps/checkout-page-map.js
@@ -0,0 +1,728 @@
+// map.setOptions({
+// disableDefaultUI: true,
+// Overwrite map options
+// https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions
+// })
+
+/* Get our global map variables */
+const map = window.lpac_map;
+const marker = window.lpac_marker;
+const infowindow = window.lpac_infowindow;
+
+const geocoder = new google.maps.Geocoder()
+
+const find_location_btn = document.querySelector("#lpac-find-location-btn");
+
+if (typeof (find_location_btn) !== 'undefined' && find_location_btn !== null) {
+ find_location_btn.addEventListener(
+ "click",
+ () => {
+ lpac_bootstrap_map_functionality(geocoder, map, infowindow)
+ }
+ )
+} else {
+ console.log('LPAC: Detect location button not present, skipping...')
+}
+
+function get_navigator_coordinates() {
+
+ return new Promise(
+ function (resolve, reject) {
+
+ if (navigator.geolocation) {
+ navigator.geolocation.getCurrentPosition(resolve, reject)
+ } else {
+ // TODO add input fields so users can change this text
+ alert('Geolocation is not possible on this web browser. Please switch to a different web browser to use our interactive map.');
+ }
+
+ }
+ ).catch(
+ function (error) {
+
+ console.log('Location Picker At Checkout Plugin: ' + error.message)
+
+ if (error.code === 1) {
+ // TODO add input fields so users can change this text
+ alert("Something went wrong while trying to detect your location. Click on the location icon in the address bar and allow our website to detect your location. Please contact us if you need additional assistance.");
+ return
+ }
+
+ alert(error.message);
+ }
+ )
+
+}
+
+/**
+ * Setup our conditional hiding of map based on selected shipping methods;
+ *
+ * Running this function as soon as the page loads allows map to be hidden quicker than on document ready event.
+ */
+lpac_hide_show_map_by_shipping_method();
+
+/**
+* Bootstrap the functionality of the map and marker.
+*/
+async function lpac_bootstrap_map_functionality(geocoder, map, infowindow) {
+
+ const position = await get_navigator_coordinates();
+
+ if (!position) {
+ console.log('Location Picker At Checkout Plugin: Position object is empty. Navigator might be disabled or this site might be detected as insecure.')
+ return;
+ }
+
+ let latitude = position.coords.latitude
+ let longitude = position.coords.longitude
+
+ const latlng = {
+ lat: parseFloat(latitude),
+ lng: parseFloat(longitude),
+ }
+
+ /**
+ * Place our initial map marker.
+ */
+ lpac_setup_initial_map_marker_position(latlng)
+
+ /**
+ * Fill in latitude and longitude fields.
+ */
+ lpac_fill_in_latlng(latlng);
+
+}
+
+/**
+ * Function getting address details from latitude and longitudes.
+ */
+async function lpac_geocode_coordinates(latlng) {
+
+ var address_array = '';
+
+ await geocoder.geocode({ location: latlng }, (results, status) => {
+
+ if (status === "OK") {
+
+ if (results[ 0 ]) {
+
+ address_array = results;
+
+ } else {
+ window.alert("No results found")
+ return;
+ }
+ } else {
+ console.log("Geocoder failed due to: " + status)
+ return
+ }
+
+ }
+
+ ).then(
+ function (resolved) {
+
+ map.panTo(latlng);
+
+ }
+ ).catch(
+ function (error) {
+
+ console.log(error)
+ // TODO Add error messages below map
+
+ if (error.code === 'OVER_QUERY_LIMIT') {
+ // TODO Localize this string
+ error_msg = 'Slow down, you are moving too quickly, use the zoom out button to move the marker across larger distances.';
+ alert(error_msg)
+ location.reload()
+ }
+
+ }
+ )
+
+ return address_array;
+
+}
+
+/**
+* Setup the intial marker location.
+*/
+async function lpac_setup_initial_map_marker_position(latlng) {
+
+ const results = await lpac_geocode_coordinates(latlng);
+
+ if (!results[ 0 ]) {
+ return
+ }
+
+ map.setZoom(16);
+ map.setCenter(latlng);
+
+ marker.setPosition(latlng);
+
+ const detected_address = results[ 0 ].formatted_address;
+
+ infowindow.setContent(detected_address);
+ infowindow.open(map, marker);
+
+ lpac_fill_in_address_fields(results, latlng);
+ lpac_marker_listen_to_drag();
+ lpac_map_listen_to_clicks();
+
+}
+
+/**
+* Handle clicking of map so marker, fields and coordinates inputs get filled in.
+*/
+function lpac_map_listen_to_clicks() {
+
+ map.addListener('click',
+ async function (event) {
+
+ const results = await lpac_geocode_coordinates(event.latLng);
+
+ if (!results[ 0 ]) {
+ console.log('LPAC: Results not as expected. See lpac_map_listen_to_clicks()')
+ return;
+ }
+
+ const lat = event.latLng.lat()
+ const lng = event.latLng.lng()
+
+ const latLng = {
+ lat: parseFloat(lat),
+ lng: parseFloat(lng),
+ }
+
+ lpac_fill_in_address_fields(results, latLng);
+
+ marker.setPosition(event.latLng)
+
+ const detected_address = results[ 0 ].formatted_address;
+
+ infowindow.setContent(detected_address);
+ infowindow.open(map, marker);
+
+ });
+
+}
+window.lpac_map_listen_to_clicks = lpac_map_listen_to_clicks;
+
+/**
+* Handle dragging of marker so fields and coordinates inputs get filled in.
+*/
+function lpac_marker_listen_to_drag() {
+
+ google.maps.event.addListener(
+ marker,
+ 'dragend',
+ async function (event) {
+
+ const moved_to_lat = event.latLng.lat()
+ const moved_to_lng = event.latLng.lng()
+
+ const moved_to_latlng = {
+ lat: parseFloat(moved_to_lat),
+ lng: parseFloat(moved_to_lng),
+ }
+
+ let results = await lpac_geocode_coordinates(moved_to_latlng);
+
+ if (!results[ 0 ]) {
+ console.log('Results not as expected. See lpac_marker_listen_to_drag()')
+ return;
+ }
+
+ let moved_to_address = results[ 0 ].formatted_address
+ infowindow.setContent(moved_to_address)
+
+ lpac_fill_in_address_fields(results, moved_to_latlng)
+
+ }
+
+ )
+
+}
+window.lpac_marker_listen_to_drag = lpac_marker_listen_to_drag;
+
+/**
+* Function responsible filling in the latitude and longitude fields.
+*/
+function lpac_fill_in_latlng(latlng) {
+
+ if (!latlng.lat || !latlng.lng) {
+ console.log('Location Picker At Checkout Plugin: Empty latlng. See lpac_fill_in_latlng()');
+ return;
+ }
+
+ let latitude = document.querySelector('#lpac_latitude');
+ let longitude = document.querySelector('#lpac_longitude');
+
+ if (typeof (latitude) === 'undefined' || latitude === null) {
+ console.log('LPAC: Can\'t find latitude and longitude input areas. Can\'t insert location coordinates.');
+ }
+
+ if (typeof (longitude) === 'undefined' || longitude === null) {
+ console.log('LPAC: Can\'t find latitude and longitude input areas. Can\'t insert location coordinates.');
+ }
+
+ latitude.value = latlng.lat
+ longitude.value = latlng.lng
+
+}
+
+/**
+* Function responsible for ochestrating the address filling methods.
+*/
+function lpac_fill_in_address_fields(results, latLng = '') {
+
+ lpac_fill_in_latlng(latLng)
+
+ lpac_fill_in_shipping_country_region(results)
+ lpac_fill_in_shipping_full_address(results)
+ lpac_fill_in_shipping_town_city(results)
+ lpac_fill_in_shipping_state_county(results)
+ lpac_fill_in_shipping_zipcode(results)
+
+ if (typeof (map_options) === 'undefined' || map_options === null) {
+ console.log('LPAC: map_options object not present, skipping...')
+ return;
+ }
+
+ const lpac_autofill_billing_fields = map_options.lpac_autofill_billing_fields
+
+ if (lpac_autofill_billing_fields) {
+ lpac_fill_in_billing_country_region(results)
+ lpac_fill_in_billing_full_address(results)
+ lpac_fill_in_billing_town_city(results)
+ lpac_fill_in_billing_state_county(results)
+ lpac_fill_in_billing_zipcode(results)
+ }
+
+}
+
+/*
+* Get country from map.
+*/
+function lpac_get_country(results) {
+
+ if (!results[ 0 ]) {
+ return;
+ }
+
+ var country = ''
+ const country_array = results[ 0 ].address_components.find(addr => addr.types[ 0 ] === "country")
+
+ if (country_array) {
+ country = country_array.short_name
+ }
+
+ return country;
+}
+
+/*
+* Get full formatted address
+*/
+function lpac_get_full_address(results) {
+
+ if (!results[ 0 ]) {
+ return;
+ }
+
+ const full_address = results[ 0 ].formatted_address
+
+ return full_address;
+}
+
+/*
+* Get Town/City
+*/
+function lpac_get_town_city(results) {
+
+ if (!results[ 0 ]) {
+ return;
+ }
+
+ var town_city = ''
+ const town_city_array = results[ 0 ].address_components.find(addr => addr.types[ 0 ] === "locality")
+ const town_city_array2 = results[ 0 ].address_components.find(addr => addr.types[ 0 ] === "postal_town")
+
+ /*
+ * Locality "locality" is used because its most commonly available.
+ */
+ if (town_city_array) {
+ town_city = town_city_array.long_name
+ }
+
+ /*
+ * But we override Locality with the more standard "postal_town" field if it exists.
+ */
+ if (town_city_array2) {
+ town_city = town_city_array2.long_name
+ }
+
+ return town_city;
+}
+
+/*
+* Get State/County
+*/
+function lpac_get_state_county(results) {
+
+ if (!results[ 0 ]) {
+ return;
+ }
+
+ let address_component = '';
+
+ for (let address_component of results[ 0 ].address_components) {
+ for (type of address_component.types) {
+ if (type === 'administrative_area_level_1') {
+ return address_component;
+ }
+ }
+
+ }
+
+ return address_component;
+
+}
+
+/*
+* Get State/County
+*/
+function lpac_get_zip_code(results) {
+
+ if (!results[ 0 ]) {
+ return;
+ }
+
+ var zipcode = ''
+ const zipcode_array = results[ 0 ].address_components.find(addr => addr.types[ 0 ] === "postal_code")
+
+ if (zipcode_array) {
+ zipcode = zipcode_array.short_name
+ }
+
+ return zipcode;
+
+}
+
+/*
+* Fill in shipping country field
+*/
+function lpac_fill_in_shipping_country_region(results) {
+
+ const shipping_country = document.querySelector('#shipping_country');
+
+ if (typeof (shipping_country) === 'undefined' || shipping_country === null) {
+ return;
+ }
+
+ shipping_country.value = lpac_get_country(results);
+
+ shipping_country.dispatchEvent(new Event('change', { 'bubbles': true })) // ensure Select2 sees the change
+
+}
+
+/*
+* Fill in billing country field
+*/
+function lpac_fill_in_billing_country_region(results) {
+
+ const billing_country = document.querySelector('#billing_country');
+
+ if (typeof (billing_country) === 'undefined' || billing_country === null) {
+ return;
+ }
+
+ billing_country.value = lpac_get_country(results);
+ billing_country.dispatchEvent(new Event('change', { 'bubbles': true })) // ensure Select2 sees the change
+
+}
+
+/*
+* Fill in shipping street address field
+*/
+function lpac_fill_in_shipping_full_address(results) {
+
+ const full_shipping_address = document.querySelector('#shipping_address_1');
+
+ if (typeof (full_shipping_address) === 'undefined' || full_shipping_address === null) {
+ return;
+ }
+
+ full_shipping_address.value = lpac_get_full_address(results);
+
+}
+
+/*
+* Fill in billing street address field
+*/
+function lpac_fill_in_billing_full_address(results) {
+
+ const full_billing_address = document.querySelector('#billing_address_1');
+
+ if (typeof (full_billing_address) === 'undefined' || full_billing_address === null) {
+ return;
+ }
+
+ full_billing_address.value = lpac_get_full_address(results);
+
+}
+
+/*
+* Fill in shipping Town/City field
+*/
+function lpac_fill_in_shipping_town_city(results) {
+
+ const shipping_city = document.querySelector('#shipping_city');
+
+ if (typeof (shipping_city) === 'undefined' || shipping_city === null) {
+ return;
+ }
+
+ shipping_city.value = lpac_get_town_city(results);
+
+}
+
+/*
+* Fill in billing Town/City field
+*/
+function lpac_fill_in_billing_town_city(results) {
+
+ const billing_city = document.querySelector('#billing_city');
+
+ if (typeof (billing_city) === 'undefined' && billing_city === null) {
+ return;
+ }
+
+ billing_city.value = lpac_get_town_city(results);
+
+}
+
+/*
+* Fill in shipping State/County field
+*/
+function lpac_fill_in_shipping_state_county(results) {
+
+ /*
+ * If we have values in our lpac_get_state_county() function
+ */
+ if (lpac_get_state_county(results)) {
+
+ /*
+ * This field changes based on the country.
+ * For some countries WC shows a text input and others it shows a dropdown
+ * We need to get the field everytime or risk JS not being able to set it.
+ */
+ const shipping_state_field = document.querySelector('#shipping_state');
+
+ if (typeof (shipping_state_field) === 'undefined' || shipping_state_field === null) {
+ return;
+ }
+
+ if (shipping_state_field.classList.contains('select2-hidden-accessible')) {
+
+ shipping_state_field.value = lpac_get_state_county(results).short_name
+
+ shipping_state_field.dispatchEvent(new Event('change', { 'bubbles': true })) // ensure Select2 sees the change
+
+ } else {
+
+ shipping_state_field.value = lpac_get_state_county(results).long_name
+
+ }
+ }
+
+}
+
+
+/*
+* Fill in billing State/County field
+*/
+function lpac_fill_in_billing_state_county(results) {
+
+ if (lpac_get_state_county(results)) {
+
+ /*
+ * This field changes based on the country.
+ * For some countries WC shows a text input and others it shows a dropdown
+ * We need to get the field everytime or risk JS not being able to set it.
+ */
+ const billing_state_field = document.querySelector('#billing_state');
+
+ if (typeof (billing_state_field) === 'undefined' || billing_state_field === null) {
+ return;
+ }
+
+ if (billing_state_field.classList.contains('select2-hidden-accessible')) {
+
+ billing_state_field.value = lpac_get_state_county(results).short_name
+ billing_state_field.dispatchEvent(new Event('change', { 'bubbles': true })) // ensure Select2 sees the change
+
+ } else {
+
+ billing_state_field.value = lpac_get_state_county(results).long_name
+
+ }
+
+ }
+
+}
+
+/*
+* Fill in shipping Zipcode field
+*/
+function lpac_fill_in_shipping_zipcode(results) {
+
+ const shipping_zipcode = document.querySelector('#shipping_postcode');
+
+ if (typeof (shipping_zipcode) === 'undefined' || shipping_zipcode === null) {
+ return;
+ }
+
+ shipping_zipcode.value = lpac_get_zip_code(results);
+
+}
+
+/*
+* Fill in billing Zipcode field
+*/
+function lpac_fill_in_billing_zipcode(results) {
+
+ const billing_zipcode = document.querySelector('#billing_postcode');
+
+ if (typeof (billing_zipcode) === 'undefined' || billing_zipcode === null) {
+ return;
+ }
+
+ billing_zipcode.value = lpac_get_zip_code(results);
+}
+
+/**
+ * Show or hide the map based ons hipping method selected
+ */
+function lpac_hide_show_map_by_shipping_method() {
+
+ const lpacShippingMethods = document.querySelectorAll('#shipping_method .shipping_method');
+
+ if (typeof (lpacShippingMethods) === 'undefined' || lpacShippingMethods === null) {
+ console.log('LPAC: Cannot find shipping methods element, skipping...');
+ return;
+ }
+
+ // This saved_disallowed_shipping_methods option is in the global JS scope
+ // See Lpac\Views\Frontend::lpac_expose_map_settings_js()
+ if (typeof (saved_disallowed_shipping_methods) === 'undefined' || saved_disallowed_shipping_methods === null) {
+ console.log('LPAC: Cannot find chosen disallowed shipping methods, skipping...');
+ return;
+ }
+
+ const disallowed_shipping_methods = saved_disallowed_shipping_methods;
+
+ let show = true;
+
+ loop1:
+ for (const lpacShippingMethod of lpacShippingMethods) {
+
+ // We have to check for the hidden type as well because if only one shipping method is available WC doesn't show radio buttons.
+ if (lpacShippingMethod.checked || lpacShippingMethod.type === 'hidden') {
+
+ loop2:
+ for (const disallowed_shipping_method of disallowed_shipping_methods) {
+
+ if (lpacShippingMethod.value.indexOf(disallowed_shipping_method) >= 0) {
+ show = false;
+ break loop1;
+ }
+
+ }
+
+ }
+
+ }
+
+ if (show) {
+ document.querySelector('#lpac-map-container').style.display = "block";
+ document.querySelector('#lpac_is_map_shown').value = 1;
+ } else {
+ document.querySelector('#lpac-map-container').style.display = "none";
+ document.querySelector('#lpac_is_map_shown').value = 0;
+ }
+
+}
+
+/**
+ * Detect the shipping method on page load
+ *
+ * This function isn't in use. It causes a slight flicker of the map due to the interval checking
+ * Function remains in place for debugging purposes.
+ *
+ */
+function lpac_setup_changed_shipping_method_on_load() {
+
+ let stateCheck = setInterval(() => {
+ if (document.readyState === 'complete') {
+ lpac_hide_show_map_by_shipping_method();
+ clearInterval(stateCheck);
+ }
+ console.log('checking..');
+ }, 100);
+
+}
+
+/**
+ * Was previously used to change map shown field value. But we're checking
+ * to see if the field is empty in Lpac\Views\Frontend::lpac_save_cords_order_meta()
+ */
+// function lpac_check_map_visibility(){
+
+// var map_div = document.querySelector( '#lpac-map-container' );
+// var map_shown = document.querySelector( '#lpac_is_map_shown' );
+// var map_present = true;
+// var map_visibility = '';
+
+// if( typeof( map_shown ) === 'undefined' || map_shown === null ){
+// console.log('LPAC: map_shown object not present, skipping...');
+// return;
+// }
+
+// /**
+// * Detect if map is present and the display property
+// */
+// if( typeof( map_div ) === 'undefined' || map_div === null ){
+// map_present = false;
+// }else{
+// map_visibility = map_div.style.display;
+// }
+
+// if ( map_present === false || map_visibility === 'none' ) {
+
+// if ( map_shown ) {
+// map_shown.value = 0
+// }
+
+// } else {
+// map_shown.value = 1
+// }
+
+// }
+
+/**
+ * Detect when shipping methods are changed based on WC custom updated_checkout event.
+ * This event can't be accessed via vanilla JS but is the most reliable for performing this action.
+ */
+(function ($) {
+ 'use strict';
+
+ $(document).ready(
+ function () {
+
+ $(document.body).on('updated_checkout', lpac_hide_show_map_by_shipping_method);
+
+ }
+ );
+
+})(jQuery);
diff --git a/includes/public/js/maps/order-details-map.js b/assets/public/js/maps/order-details-map.js
similarity index 54%
rename from includes/public/js/maps/order-details-map.js
rename to assets/public/js/maps/order-details-map.js
index f7e6747..d482e93 100644
--- a/includes/public/js/maps/order-details-map.js
+++ b/assets/public/js/maps/order-details-map.js
@@ -1,11 +1,14 @@
-function lpac_setup_order_details_map(){
+function lpac_setup_order_details_map() {
- if( typeof(map) === 'undefined' || map === null ){
+ const map = window.lpac_map;
+ const infowindow = window.lpac_infowindow;
+
+ if (typeof (map) === 'undefined' || map === null) {
console.log('LPAC: map object not present, skipping...')
return;
}
- if( typeof(map_options) === 'undefined' || map_options === null ){
+ if (typeof (map_options) === 'undefined' || map_options === null) {
console.log('LPAC: map_options object not present, skipping...')
return;
}
@@ -19,19 +22,21 @@ function lpac_setup_order_details_map(){
gestureHandling: 'none',
}
);
-
+
const latlng = {
lat: map_options.lpac_map_order_latitude,
lng: map_options.lpac_map_order_longitude,
};
-
+
const marker = new google.maps.Marker({
- position: latlng,
- map: map,
- cursor: 'default'
- });
+ position: latlng,
+ map: map,
+ cursor: 'default'
+ });
+
+ infowindow.setContent(` ${map_options.lpac_map_order_shipping_address_1}
${map_options.lpac_map_order_shipping_address_2}
`);
+ infowindow.open(map, marker);
-
}
lpac_setup_order_details_map();
diff --git a/includes/public/js/maps/order-received-map.js b/assets/public/js/maps/order-received-map.js
similarity index 60%
rename from includes/public/js/maps/order-received-map.js
rename to assets/public/js/maps/order-received-map.js
index e5163a0..302fe0f 100644
--- a/includes/public/js/maps/order-received-map.js
+++ b/assets/public/js/maps/order-received-map.js
@@ -1,15 +1,18 @@
-function lpac_setup_order_received_map(){
+function lpac_setup_order_received_map() {
- if( typeof(map) === 'undefined' || map === null ){
+ const map = window.lpac_map;
+ const infowindow = window.lpac_infowindow;
+
+ if (typeof (map) === 'undefined' || map === null) {
console.log('LPAC: map object not present, skipping...')
return;
}
- if( typeof(map_options) === 'undefined' || map_options === null ){
+ if (typeof (map_options) === 'undefined' || map_options === null) {
console.log('LPAC: map_options object not present, skipping...')
return;
}
-
+
map.setOptions(
{
center: { lat: map_options.lpac_map_order_latitude, lng: map_options.lpac_map_order_longitude },
@@ -19,20 +22,23 @@ function lpac_setup_order_received_map(){
gestureHandling: 'none',
}
);
-
+
const latlng = {
lat: map_options.lpac_map_order_latitude,
lng: map_options.lpac_map_order_longitude,
};
-
+
const marker = new google.maps.Marker(
{
position: latlng,
map: map,
cursor: 'default'
- }
+ }
);
-
+
+ infowindow.setContent(` ${map_options.lpac_map_order_shipping_address_1}
${map_options.lpac_map_order_shipping_address_2}
`);
+ infowindow.open(map, marker);
+
}
lpac_setup_order_received_map();
diff --git a/assets/screenshot-1.png b/assets/screenshot-1.png
deleted file mode 100644
index 90310d8..0000000
Binary files a/assets/screenshot-1.png and /dev/null differ
diff --git a/assets/screenshot-2.png b/assets/screenshot-2.png
deleted file mode 100644
index ec802ad..0000000
Binary files a/assets/screenshot-2.png and /dev/null differ
diff --git a/assets/screenshot-3.png b/assets/screenshot-3.png
deleted file mode 100644
index dfb18af..0000000
Binary files a/assets/screenshot-3.png and /dev/null differ
diff --git a/assets/screenshot-4.png b/assets/screenshot-4.png
deleted file mode 100644
index bbca1b6..0000000
Binary files a/assets/screenshot-4.png and /dev/null differ
diff --git a/assets/screenshot-5.png b/assets/screenshot-5.png
deleted file mode 100644
index 346c77d..0000000
Binary files a/assets/screenshot-5.png and /dev/null differ
diff --git a/bin/freemius-prep.sh b/bin/freemius-prep.sh
index a9eb3fe..0a45877 100644
--- a/bin/freemius-prep.sh
+++ b/bin/freemius-prep.sh
@@ -13,9 +13,10 @@ mkdir -p artifact
# Remove dev dependencies
composer install --no-dev
+composer dumpautoload
-# Sync SVN
-# rsync -acvP --delete --exclude-from=".distignore" ./ "$LPAC_SVN"
+# Build our JS files with parcel
+npm run-script build
# Sync dist folder
rsync -acvP --delete --exclude-from=".distignore" ./ "./dist"
@@ -23,6 +24,10 @@ rsync -acvP --delete --exclude-from=".distignore" ./ "./dist"
#Change to our dist folder and zip to artifact folder
(cd dist && zip -r ../artifact/lpac.zip .)
+# Delete dist folder
+rm -rf dist
+
# Re-add dev dependencies
composer install
+composer dumpautoload
diff --git a/bin/github-lite-prep.sh b/bin/github-lite-prep.sh
index 936563f..ec46530 100644
--- a/bin/github-lite-prep.sh
+++ b/bin/github-lite-prep.sh
@@ -13,6 +13,7 @@ mkdir -p artifact
# Remove dev dependencies
composer install --no-dev
+composer dumpautoload
# Sync dist folder
rsync -acvP --delete --exclude-from=".distignore-github-lite" ./ "./dist"
@@ -22,4 +23,5 @@ rsync -acvP --delete --exclude-from=".distignore-github-lite" ./ "./dist"
# Re-add dev dependencies
composer install
+composer dumpautoload
diff --git a/class-lpac-uninstall.php b/class-lpac-uninstall.php
index 26125d6..2a4f6de 100644
--- a/class-lpac-uninstall.php
+++ b/class-lpac-uninstall.php
@@ -72,6 +72,7 @@ public static function remove_plugin_settings() {
'lpac_enable_save_address_feature',
'lpac_wc_shipping_methods',
'lpac_hide_troubleshooting_admin_checkout_notice',
+ 'lpac_dequeue_google_maps',
);
foreach ( $option_keys as $key ) {
diff --git a/composer.json b/composer.json
index 1df30f4..c546139 100644
--- a/composer.json
+++ b/composer.json
@@ -6,11 +6,16 @@
"github-lite": "sh bin/github-lite-prep.sh"
},
"require-dev": {
- "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
- "wp-coding-standards/wpcs": "^2.3"
+ "dealerdirect/phpcodesniffer-composer-installer": "0.7.1",
+ "wp-coding-standards/wpcs": "2.3"
},
"require": {
- "freemius/wordpress-sdk": "^2.4",
- "endroid/qr-code": "^4.1"
+ "freemius/wordpress-sdk": "2.4.2",
+ "endroid/qr-code": "4.3.5"
+ },
+ "autoload":{
+ "psr-4": {
+ "Lpac\\" : "includes/"
+ }
}
}
diff --git a/composer.lock b/composer.lock
index 554b7a3..be845d9 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "3dba8734a6540053cf2ecb760db7ef69",
+ "content-hash": "0982f709642a1ed8a7b7ba0de5689423",
"packages": [
{
"name": "bacon/bacon-qr-code",
@@ -100,16 +100,16 @@
},
{
"name": "endroid/qr-code",
- "version": "4.1.4",
+ "version": "4.3.5",
"source": {
"type": "git",
"url": "https://github.com/endroid/qr-code.git",
- "reference": "f38ff0d968788aef0ddefb957062024b4ea521e1"
+ "reference": "5630e192948b466d418608ecce697465d20260af"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/endroid/qr-code/zipball/f38ff0d968788aef0ddefb957062024b4ea521e1",
- "reference": "f38ff0d968788aef0ddefb957062024b4ea521e1",
+ "url": "https://api.github.com/repos/endroid/qr-code/zipball/5630e192948b466d418608ecce697465d20260af",
+ "reference": "5630e192948b466d418608ecce697465d20260af",
"shasum": ""
},
"require": {
@@ -164,7 +164,7 @@
"type": "github"
}
],
- "time": "2021-05-08T14:30:54+00:00"
+ "time": "2021-09-17T07:50:43+00:00"
},
{
"name": "freemius/wordpress-sdk",
diff --git a/includes/admin/class-lpac-admin.php b/includes/Bootstrap/Admin_Enqueues.php
similarity index 80%
rename from includes/admin/class-lpac-admin.php
rename to includes/Bootstrap/Admin_Enqueues.php
index c42321e..5e4ce65 100644
--- a/includes/admin/class-lpac-admin.php
+++ b/includes/Bootstrap/Admin_Enqueues.php
@@ -7,11 +7,12 @@
* @since 1.0.0
*
* @package Lpac
- * @subpackage Lpac/admin
* @author Uriahs Victor
*
*/
-class Lpac_Admin
+namespace Lpac\Bootstrap;
+
+class Admin_Enqueues
{
/**
* The ID of this plugin.
@@ -71,7 +72,7 @@ public function enqueue_styles()
*/
wp_enqueue_style(
$this->plugin_name,
- plugin_dir_url( __FILE__ ) . 'css/lpac-admin.css',
+ LPAC_PLUGIN_ASSETS_PATH_URL . 'admin/css/lpac-admin.css',
array(),
$this->version,
'all'
@@ -98,21 +99,26 @@ public function enqueue_scripts()
*/
wp_enqueue_script(
$this->plugin_name,
- plugin_dir_url( __FILE__ ) . 'js/lpac-admin.js',
+ LPAC_PLUGIN_ASSETS_PATH_URL . 'admin/js/lpac-admin.js',
array( 'jquery' ),
$this->version,
false
);
/**
- * Enqueue Google Maps script
+ * Register Google Map Script
*/
- wp_enqueue_script(
- $this->plugin_name . '-google-maps-js',
- $this->lpac_google_maps_resource,
- array(),
- $this->version,
- false
- );
+
+ if ( get_option( 'lpac_dequeue_google_maps' ) !== 'dashboard' && get_option( 'lpac_dequeue_google_maps' ) !== 'both' ) {
+ wp_register_script(
+ $this->plugin_name . '-google-maps-js',
+ $this->lpac_google_maps_resource,
+ array(),
+ $this->version,
+ false
+ );
+ wp_enqueue_script( $this->plugin_name . '-google-maps-js' );
+ }
+
/**
* This has to be enqueued in the footer so our wp_add_inline_script() function can work.
* Only run this code on shop order(order details) page in admin area.
@@ -120,8 +126,8 @@ public function enqueue_scripts()
if ( get_current_screen()->id === 'shop_order' ) {
wp_enqueue_script(
$this->plugin_name . '-order-map',
- plugin_dir_url( __FILE__ ) . 'js/order-map.js',
- array( $this->plugin_name . '-google-maps-js' ),
+ LPAC_PLUGIN_ASSETS_PATH_URL . 'admin/js/order-map.js',
+ array(),
$this->version,
true
);
diff --git a/includes/public/class-lpac-public.php b/includes/Bootstrap/Frontend_Enqueues.php
similarity index 59%
rename from includes/public/class-lpac-public.php
rename to includes/Bootstrap/Frontend_Enqueues.php
index 34eedec..c2cefbe 100644
--- a/includes/public/class-lpac-public.php
+++ b/includes/Bootstrap/Frontend_Enqueues.php
@@ -16,10 +16,12 @@
* enqueue the public-facing stylesheet and JavaScript.
*
* @package Lpac
- * @subpackage Lpac/public
* @author Uriahs Victor
*/
-class Lpac_Public
+namespace Lpac\Bootstrap;
+
+use Lpac\Helpers\Functions as Functions_Helper ;
+class Frontend_Enqueues
{
/**
* The ID of this plugin.
@@ -37,22 +39,6 @@ class Lpac_Public
* @var string $version The current version of this plugin.
*/
private $version ;
- /**
- * The Google Maps CDN link.
- *
- * @since 1.0.0
- * @access private
- * @var string $lpac_google_maps_link The Google Maps CDN link.
- */
- private $lpac_google_maps_link ;
- /**
- * The Google Maps API Key.
- *
- * @since 1.0.0
- * @access private
- * @var string $lpac_google_api_key The Google Maps API Key.
- */
- private $lpac_google_api_key ;
/**
* The full google maps resource with all needed params.
*
@@ -95,7 +81,7 @@ public function enqueue_styles()
*/
wp_enqueue_style(
$this->plugin_name,
- plugin_dir_url( __FILE__ ) . 'css/lpac-public.css',
+ LPAC_PLUGIN_ASSETS_PATH_URL . 'public/css/lpac-public.css',
array(),
$this->version,
'all'
@@ -120,9 +106,10 @@ public function enqueue_scripts()
* between the defined hooks and the functions defined in this
* class.
*/
+ $path = ( LPAC_DEBUG ? '' : 'build/' );
wp_enqueue_script(
$this->plugin_name,
- plugin_dir_url( __FILE__ ) . 'js/lpac-public.js',
+ LPAC_PLUGIN_ASSETS_PATH_URL . 'public/js/lpac-public.js',
array( 'jquery' ),
$this->version,
false
@@ -130,15 +117,15 @@ public function enqueue_scripts()
// Only enqueue the Google Map CDN script on the needed pages
if ( is_wc_endpoint_url( 'view-order' ) || is_wc_endpoint_url( 'order-received' ) || is_checkout() ) {
- $show_on_view_order_page = Lpac_Functions_Helper::lpac_show_map( 'lpac_display_map_on_view_order_page' );
+ $show_on_view_order_page = Functions_Helper::lpac_show_map( 'lpac_display_map_on_view_order_page' );
if ( is_wc_endpoint_url( 'view-order' ) && $show_on_view_order_page === false ) {
return;
}
- $show_on_order_received_page = Lpac_Functions_Helper::lpac_show_map( 'lpac_display_map_on_order_received_page' );
+ $show_on_order_received_page = Functions_Helper::lpac_show_map( 'lpac_display_map_on_order_received_page' );
if ( is_wc_endpoint_url( 'order-received' ) && $show_on_order_received_page === false ) {
return;
}
- $show_on_checkout_page = Lpac_Functions_Helper::lpac_show_map( 'checkout' );
+ $show_on_checkout_page = Functions_Helper::lpac_show_map( 'checkout' );
/**
* is_checkout() also runs on is_wc_endpoint_url( 'order-received' ) so we need to make this if block doesn't
* by added the ! conditional
@@ -147,35 +134,41 @@ public function enqueue_scripts()
return;
}
/**
- * Load Google Map from CDN
+ * Register Google Map Script
*/
- wp_enqueue_script(
- LPAC_PLUGIN_NAME . '-google-maps-js',
- $this->lpac_google_maps_resource,
- array(),
- LPAC_VERSION,
- false
- );
+
+ if ( get_option( 'lpac_dequeue_google_maps' ) !== 'frontend' && get_option( 'lpac_dequeue_google_maps' ) !== 'both' ) {
+ wp_register_script(
+ $this->plugin_name . '-google-maps-js',
+ $this->lpac_google_maps_resource,
+ array(),
+ $this->version,
+ false
+ );
+ wp_enqueue_script( $this->plugin_name . '-google-maps-js' );
+ }
+
/**
* The following javascript files have to be enqueued in the footer so our wp_add_inline_script() function can work.
*/
/**
- * Base Map JS
+ * Base Map JS, also enqueues google maps JS automatically.
*/
wp_enqueue_script(
$this->plugin_name . '-base-map',
- plugin_dir_url( __FILE__ ) . 'js/maps/base-map.js',
- array( $this->plugin_name . '-google-maps-js' ),
+ LPAC_PLUGIN_ASSETS_PATH_URL . 'public/js/maps/' . $path . 'base-map.js',
+ array(),
$this->version,
true
);
+ // wp_enqueue_script( $this->plugin_name . '-base-map', LPAC_PLUGIN_ASSETS_PATH_URL . 'public/js/maps/base-map.js', array( $this->plugin_name . '-google-maps-js' ), $this->version, true );
/**
* Load order received page map
*/
if ( is_wc_endpoint_url( 'order-received' ) ) {
wp_enqueue_script(
$this->plugin_name . '-order-received-map',
- plugin_dir_url( __FILE__ ) . 'js/maps/order-received-map.js',
+ LPAC_PLUGIN_ASSETS_PATH_URL . 'public/js/maps/' . $path . 'order-received-map.js',
array( $this->plugin_name . '-base-map' ),
$this->version,
true
@@ -187,7 +180,7 @@ public function enqueue_scripts()
if ( is_wc_endpoint_url( 'view-order' ) ) {
wp_enqueue_script(
$this->plugin_name . '-order-details-map',
- plugin_dir_url( __FILE__ ) . 'js/maps/order-details-map.js',
+ LPAC_PLUGIN_ASSETS_PATH_URL . 'public/js/maps/' . $path . 'order-details-map.js',
array( $this->plugin_name . '-base-map' ),
$this->version,
true
@@ -203,7 +196,7 @@ public function enqueue_scripts()
*/
wp_enqueue_script(
$this->plugin_name . '-checkout-page-map',
- plugin_dir_url( __FILE__ ) . 'js/maps/checkout-page-map.js',
+ LPAC_PLUGIN_ASSETS_PATH_URL . 'public/js/maps/' . $path . 'checkout-page-map.js',
array( $this->plugin_name . '-base-map' ),
$this->version,
true
@@ -212,53 +205,5 @@ public function enqueue_scripts()
}
}
-
- /**
- * Map settings.
- *
- * @since 1.0.0
- */
- public function lpac_get_map_settings()
- {
- $starting_coordinates = get_option( 'lpac_map_starting_coordinates', '14.024519,-60.974876' );
- $starting_coordinates = apply_filters( 'lpac_map_starting_coordinates', $starting_coordinates );
- $coordinates_parts = explode( ',', $starting_coordinates );
- $latitude = ( !empty($coordinates_parts[0]) ? (double) $coordinates_parts[0] : (double) 14.024519 );
- $longitude = ( !empty($coordinates_parts[1]) ? (double) $coordinates_parts[1] : (double) -60.974876 );
- $zoom_level = (int) get_option( 'lpac_general_map_zoom_level', 16 );
- $zoom_level = apply_filters( 'lpac_general_map_zoom_level', $zoom_level );
- $clickable_icons = get_option( 'lpac_allow_clicking_on_map_icons', 'yes' );
- $clickable_icons = apply_filters( 'lpac_allow_clicking_on_map_icons', $clickable_icons );
- $background_color = get_option( 'lpac_map_background_color', '#eee' );
- $background_color = apply_filters( 'lpac_map_background_color', $background_color );
- $fill_in_billing_fields = get_option( 'lpac_autofill_billing_fields', 'yes' );
- $fill_in_billing_fields = apply_filters( 'lpac_autofill_billing_fields', $fill_in_billing_fields );
- $data = array(
- 'lpac_map_default_latitude' => $latitude,
- 'lpac_map_default_longitude' => $longitude,
- 'lpac_map_zoom_level' => $zoom_level,
- 'lpac_map_clickable_icons' => ( $clickable_icons === 'yes' ? true : false ),
- 'lpac_map_background_color' => $background_color,
- 'lpac_autofill_billing_fields' => ( $fill_in_billing_fields === 'yes' ? true : false ),
- );
- return apply_filters( 'lpac_map_stored_settings', $data );
- }
-
- /**
- * Detect needed Woocommerce pages.
- *
- * Detect if the page is one of which the map is supposed to show.
- *
- * @since 1.1.0
- *
- * @return bool Whether or not the page is one of our needed pages.
- */
- public function lpac_is_allowed_woocommerce_pages()
- {
- if ( is_wc_endpoint_url( 'view-order' ) || is_wc_endpoint_url( 'order-received' ) || is_checkout() ) {
- return true;
- }
- return false;
- }
}
\ No newline at end of file
diff --git a/includes/class-lpac-i18n.php b/includes/Bootstrap/I18n.php
similarity index 89%
rename from includes/class-lpac-i18n.php
rename to includes/Bootstrap/I18n.php
index 2d7d036..db5aa2e 100644
--- a/includes/class-lpac-i18n.php
+++ b/includes/Bootstrap/I18n.php
@@ -10,7 +10,6 @@
* @since 1.0.0
*
* @package Lpac
- * @subpackage Lpac/includes
*/
/**
@@ -24,7 +23,9 @@
* @subpackage Lpac/includes
* @author Uriahs Victor
*/
-class Lpac_i18n {
+namespace Lpac\Bootstrap;
+
+class I18n {
/**
@@ -35,13 +36,11 @@ class Lpac_i18n {
public function load_plugin_textdomain() {
load_plugin_textdomain(
- 'lpac',
+ 'map-location-picker-at-checkout-for-woocommerce',
false,
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
);
}
-
-
}
diff --git a/includes/class-lpac-loader.php b/includes/Bootstrap/Loader.php
similarity index 98%
rename from includes/class-lpac-loader.php
rename to includes/Bootstrap/Loader.php
index a473778..bc6b8c7 100644
--- a/includes/class-lpac-loader.php
+++ b/includes/Bootstrap/Loader.php
@@ -7,9 +7,8 @@
* @since 1.0.0
*
* @package Lpac
- * @subpackage Lpac/includes
*/
-
+namespace Lpac\Bootstrap;
/**
* Register all actions and filters for the plugin.
*
@@ -21,7 +20,7 @@
* @subpackage Lpac/includes
* @author Uriahs Victor
*/
-class Lpac_Loader {
+class Loader {
/**
* The array of actions registered with WordPress.
diff --git a/includes/class-lpac.php b/includes/Bootstrap/Main.php
similarity index 72%
rename from includes/class-lpac.php
rename to includes/Bootstrap/Main.php
index 64c9218..e51333e 100644
--- a/includes/class-lpac.php
+++ b/includes/Bootstrap/Main.php
@@ -10,7 +10,6 @@
* @since 1.0.0
*
* @package Lpac
- * @subpackage Lpac/includes
*/
/**
* The core plugin class.
@@ -26,7 +25,23 @@
* @subpackage Lpac/includes
* @author Uriahs Victor
*/
-class Lpac
+namespace Lpac\Bootstrap;
+
+use Lpac\Bootstrap\Loader ;
+use Lpac\Bootstrap\I18n ;
+use Lpac\Bootstrap\Admin_Enqueues ;
+use Lpac\Bootstrap\Frontend_Enqueues ;
+use Lpac\Controllers\Emails_Controller ;
+use Lpac\Views\Admin as Admin_Display ;
+use Lpac\Notices\Admin as Admin_Notices ;
+use Lpac\Views\Frontend as Frontend_Display ;
+/**
+* Class Main.
+*
+* Class responsible for firing public and admin hooks.
+*
+*/
+class Main
{
/**
* The loader that's responsible for maintaining and registering all hooks that power
@@ -81,13 +96,6 @@ public function __construct()
/**
* Load the required dependencies for this plugin.
*
- * Include the following files that make up the plugin:
- *
- * - Lpac_Loader. Orchestrates the hooks of the plugin.
- * - Lpac_i18n. Defines internationalization functionality.
- * - Lpac_Admin. Defines all hooks for the admin area.
- * - Lpac_Public. Defines all hooks for the public side of the site.
- *
* Create an instance of the loader which will be used to register the hooks
* with WordPress.
*
@@ -96,50 +104,7 @@ public function __construct()
*/
private function load_dependencies()
{
- /**
- * The class responsible for orchestrating the actions and filters of the
- * core plugin.
- */
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-lpac-loader.php';
- /**
- * The class responsible for defining internationalization functionality
- * of the plugin.
- */
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-lpac-i18n.php';
- /**
- * The class responsible for defining all actions that occur in the admin area.
- */
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/admin/class-lpac-admin.php';
- /**
- * The class responsible for defining all actions that occur in the admin-facing
- * side of the site.
- */
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/admin/class-lpac-admin-display.php';
- /**
- * The class responsible for all admin-facing notices
- */
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/admin/class-lpac-admin-notices.php';
- /**
- * The class responsible for defining static helper functions that might
- * be used in multiple classes.
- */
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/helpers/class-lpac-functions-helper.php';
- /**
- * The class responsible for defining all actions that occur in the public-facing
- * side of the site.
- */
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/public/class-lpac-public.php';
- /**
- * The class responsible for defining all actions that occur in the public-facing
- * side of the site.
- */
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/public/class-lpac-public-display.php';
- /**
- * The class responsible for generating QR Code using provided data.
- *
- */
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/public/class-lpac-qr-code-generator.php';
- $this->loader = new Lpac_Loader();
+ $this->loader = new Loader();
}
/**
@@ -153,7 +118,7 @@ private function load_dependencies()
*/
private function set_locale()
{
- $plugin_i18n = new Lpac_i18n();
+ $plugin_i18n = new I18n();
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
}
@@ -166,9 +131,9 @@ private function set_locale()
*/
private function define_admin_hooks()
{
- $plugin_admin = new Lpac_Admin();
- $plugin_admin_display = new Lpac_Admin_Display();
- $admin_notices = new Lpac_Admin_Notices();
+ $plugin_admin = new Admin_Enqueues();
+ $plugin_admin_display = new Admin_Display();
+ $admin_notices = new Admin_Notices();
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
// Notices
@@ -183,6 +148,7 @@ private function define_admin_hooks()
1
);
$this->loader->add_action( 'add_meta_boxes', $plugin_admin_display, 'lpac_create_custom_order_details_metabox' );
+ $this->loader->add_action( 'woocommerce_get_settings_pages', $plugin_admin_display, 'lpac_add_settings_tab' );
}
/**
@@ -194,9 +160,9 @@ private function define_admin_hooks()
*/
private function define_public_hooks()
{
- $plugin_public = new Lpac_Public( $this->get_plugin_name(), $this->get_version() );
- $plugin_public_display = new Lpac_Public_Display();
- $functions_helper = new Lpac_Functions_Helper();
+ $plugin_public = new Frontend_Enqueues();
+ $plugin_public_display = new Frontend_Display();
+ $controller_emails = new Emails_Controller();
/*
* If plugin not enabled don't continue
*/
@@ -207,7 +173,6 @@ private function define_public_hooks()
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
$this->loader->add_action( 'wp_head', $plugin_public_display, 'lpac_output_map_custom_styles' );
- $checkout_page_map_location = get_option( 'lpac_checkout_map_orientation', 'woocommerce_after_checkout_shipping_form' );
/*
* Output hidden input fields for latitude and longitude.
*/
@@ -215,6 +180,7 @@ private function define_public_hooks()
/*
* Output map on checkout page
*/
+ $checkout_page_map_location = get_option( 'lpac_checkout_map_orientation', 'woocommerce_before_checkout_billing_form' );
$checkout_page_map_location = apply_filters( 'lpac_checkout_map_orientation', $checkout_page_map_location );
$this->loader->add_action( $checkout_page_map_location, $plugin_public_display, 'lpac_output_map_on_checkout_page' );
/*
@@ -248,7 +214,7 @@ private function define_public_hooks()
$email_map_link_location = apply_filters( 'lpac_email_delivery_map_link_location', $email_map_link_location );
$this->loader->add_action(
$email_map_link_location,
- $plugin_public_display,
+ $controller_emails,
'lpac_add_delivery_location_link_to_email',
20,
4
diff --git a/includes/Controllers/Emails_Controller.php b/includes/Controllers/Emails_Controller.php
new file mode 100644
index 0000000..6a2a014
--- /dev/null
+++ b/includes/Controllers/Emails_Controller.php
@@ -0,0 +1,106 @@
+$button_text
+HTML;
+ echo $button;
+ }
+
+ /**
+ * Create map location QR Code link in email.
+ *
+ * @param string $link The link to google maps.
+ * @param int $order_id The current order id.
+ * @since 1.1.0
+ */
+ public function lpac_create_delivery_location_link_qrcode( $link, $order_id ) {
+
+ $options = array(
+ 'qr_code_data' => $link,
+ 'qr_code_foreground_rgb' => '0,0,0',
+ 'qr_code_background_rgb' => '255,255,255',
+ );
+
+ /*
+ * Generate and save QR Code
+ */
+ QR_Code_Generator::lpac_generate_qr_code( $options, $order_id );
+
+ /*
+ * https://example.com/wp-content/uploads/lpac-qr-codes/Y/m/d/order_id.jpg
+ */
+ $qr_code_link = Functions_Helper::lpac_get_qr_codes_directory( 'baseurl' ) . $order_id . '.jpg';
+
+ echo "";
+
+ }
+
+ /**
+ * Outputs a Button or QR Code inside order emails.
+ *
+ * @since 1.1.0
+ */
+ public function lpac_add_delivery_location_link_to_email( $order, $sent_to_admin, $plain_text, $email ) {
+
+ $allowed_emails = get_option( 'lpac_email_delivery_map_emails', array() );
+
+ if ( ! in_array( $email->id, $allowed_emails ) ) {
+ return;
+ }
+
+ $latitude = get_post_meta( $order->get_id(), '_lpac_latitude', true );
+ $longitude = get_post_meta( $order->get_id(), '_lpac_longitude', true );
+ $map_link = apply_filters( 'lpac_map_provider', "https://www.google.com/maps/search/?api=1&query=${latitude},${longitude}", $latitude, $longitude );
+
+ $map_link_type = get_option( 'lpac_email_delivery_map_link_type' );
+
+ if ( $map_link_type === 'button' ) {
+ $this->lpac_create_delivery_location_link_button( $map_link );
+ } else {
+ $this->lpac_create_delivery_location_link_qrcode( $map_link, $order->get_id() );
+ }
+
+ }
+
+}
diff --git a/includes/helpers/class-lpac-functions-helper.php b/includes/Helpers/Functions.php
similarity index 97%
rename from includes/helpers/class-lpac-functions-helper.php
rename to includes/Helpers/Functions.php
index 7a8477c..833c86f 100644
--- a/includes/helpers/class-lpac-functions-helper.php
+++ b/includes/Helpers/Functions.php
@@ -9,9 +9,10 @@
* @since 1.0.0
*
* @package Lpac
- * @subpackage Lpac/includes/helpers
*/
-class Lpac_Functions_Helper
+namespace Lpac\Helpers;
+
+class Functions
{
/**
* Shows a feature if the setting is enabled
@@ -125,7 +126,7 @@ public static function lpac_get_available_shipping_classes()
return array();
}
- $lpac_wc_shipping_classes = ( new WC_Shipping() )->get_shipping_classes();
+ $lpac_wc_shipping_classes = ( new \WC_Shipping() )->get_shipping_classes();
if ( !is_array( $lpac_wc_shipping_classes ) ) {
return array();
}
@@ -180,7 +181,7 @@ public static function lpac_get_available_shipping_methods()
return array();
}
- $zones = WC_Shipping_Zones::get_zones();
+ $zones = \WC_Shipping_Zones::get_zones();
if ( !is_array( $zones ) ) {
return array();
}
diff --git a/includes/public/class-lpac-qr-code-generator.php b/includes/Helpers/QR_Code_Generator.php
similarity index 91%
rename from includes/public/class-lpac-qr-code-generator.php
rename to includes/Helpers/QR_Code_Generator.php
index a7130b4..d0980be 100644
--- a/includes/public/class-lpac-qr-code-generator.php
+++ b/includes/Helpers/QR_Code_Generator.php
@@ -9,8 +9,9 @@
* @since 1.1.0
*
* @package Lpac
- * @subpackage Lpac/public
*/
+namespace Lpac\Helpers;
+
use Endroid\QrCode\Color\Color;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelLow;
@@ -20,8 +21,9 @@
use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin;
use Endroid\QrCode\Writer\PngWriter;
use Endroid\QrCode\Label\Font\NotoSans;
+// use Endroid\QrCode\Label\Font\OpenSans;
-class Lpac_Qr_Code_Generator {
+class QR_Code_Generator {
/**
* Creates a QR code
@@ -58,7 +60,7 @@ public static function lpac_generate_qr_code( $options, $order_id ) {
$writer = new PngWriter();
- $qr_code_label = __( 'Delivery Location', 'lpac' );
+ $qr_code_label = __( 'Delivery Location', 'map-location-picker-at-checkout-for-woocommerce' );
$qr_code_label = apply_filters( 'lpac_map_location_link_button_text', $qr_code_label );
/*
@@ -76,6 +78,9 @@ public static function lpac_generate_qr_code( $options, $order_id ) {
$label = Label::create( $qr_code_label )
->setFont( new NotoSans( 18 ) );
+ // $label = Label::create( $qr_code_label )
+ // ->setFont( new OpenSans( 18 ) );
+
$result = $writer->write( $qr_code, null, $label );
$image = $result->saveToFile( $path_with_filename );
diff --git a/includes/admin/class-lpac-admin-notices.php b/includes/Notices/Admin.php
similarity index 80%
rename from includes/admin/class-lpac-admin-notices.php
rename to includes/Notices/Admin.php
index 9b982b3..9bf6726 100644
--- a/includes/admin/class-lpac-admin-notices.php
+++ b/includes/Notices/Admin.php
@@ -9,9 +9,10 @@
* @since 1.1.0
*
* @package Lpac
-* @subpackage Lpac/inludes/admin
*/
-class Lpac_Admin_Notices {
+namespace Lpac\Notices;
+
+class Admin {
/**
* Detect if WooCommerce is active.
@@ -27,7 +28,7 @@ public function lpac_wc_not_active_notice() {
?>
- ', '', '', '' ); ?>
+ ', '', '', '' ); ?>
- ', '', '', '' ); ?>
+ ', '', '', '' ); ?>
$latitude,
- 'longitude' => $longitude,
+ $order_location_details = array(
+ 'latitude' => $latitude,
+ 'longitude' => $longitude,
+ 'shipping_address_1' => $shipping_address_1,
+ 'shipping_address_2' => $shipping_address_2,
);
- $order_coordinates = json_encode( $order_coordinates );
+ $order_location_details = json_encode( $order_location_details );
- $global_variables = <<
-
+
-DIV;
+HTML;
echo $map_container;
diff --git a/includes/admin/class-lpac-admin-settings.php b/includes/Views/Admin_Settings.php
similarity index 66%
rename from includes/admin/class-lpac-admin-settings.php
rename to includes/Views/Admin_Settings.php
index 06e2c38..903a52c 100644
--- a/includes/admin/class-lpac-admin-settings.php
+++ b/includes/Views/Admin_Settings.php
@@ -7,10 +7,12 @@
* @since 1.0.0
*
* @package Lpac
- * @subpackage Lpac/admin
* @author Uriahs Victor
*/
-class Lpac_Admin_Settings extends WC_Settings_Page
+namespace Lpac\Views;
+
+use Lpac\Helpers\Functions as Functions_Helper ;
+class Admin_Settings extends \WC_Settings_Page
{
/**
* Setting page id.
@@ -30,7 +32,7 @@ class Lpac_Admin_Settings extends WC_Settings_Page
public function __construct()
{
$this->id = 'lpac_settings';
- $this->label = __( 'Location Picker at Checkout', 'lpac' );
+ $this->label = __( 'Location Picker at Checkout', 'map-location-picker-at-checkout-for-woocommerce' );
/**
* Define all hooks instead of inheriting from parent
*/
@@ -55,10 +57,10 @@ public function __construct()
public function lpac_create_plugin_settings_sections()
{
$sections = array(
- 'general' => __( 'General', 'lpac' ),
- 'display' => __( 'Display', 'lpac' ),
- 'debug' => __( 'Debug', 'lpac' ),
- 'premium' => __( 'Premium', 'lpac' ),
+ 'general' => __( 'General', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'display' => __( 'Display', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'debug' => __( 'Debug', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'premium' => __( 'Premium', 'map-location-picker-at-checkout-for-woocommerce' ),
);
// TODO: Allow this section once development of premium features are futher ahead.
if ( lpac_fs()->is_free_plan() ) {
@@ -95,22 +97,22 @@ public function lpac_output_settings_sections()
*/
private function lpac_create_plugin_settings_banner()
{
- $here = __( 'HERE', 'lpac' );
+ $here = __( 'HERE', 'map-location-picker-at-checkout-for-woocommerce' );
$external_icon = '';
if ( empty(get_option( 'lpac_google_maps_api_key', '' )) ) {
- $no_api_key = __( 'You need an API Key to use Google Maps. Please see this document for how to get it ', 'lpac' );
+ $no_api_key = __( 'You need an API Key to use Google Maps. Please see this document for how to get it ', 'map-location-picker-at-checkout-for-woocommerce' );
$no_api_key .= "{$here}";
$no_api_key .= $external_icon;
} else {
$no_api_key = '';
}
- $title = __( "Use the Options Below to Change the Plugin's Settings", 'lpac' );
- $issues = __( 'If you encounter any issues then please open a support ticket ', 'lpac' );
+ $title = __( "Use the Options Below to Change the Plugin's Settings", 'map-location-picker-at-checkout-for-woocommerce' );
+ $issues = __( 'If you encounter any issues then please open a support ticket ', 'map-location-picker-at-checkout-for-woocommerce' );
$issues .= "{$here}";
$issues .= $external_icon;
- $translate_plugin = __( 'Plugin settings not in your Language? Help translate it ', 'lpac' );
+ $translate_plugin = __( 'Plugin settings not in your Language? Help translate it ', 'map-location-picker-at-checkout-for-woocommerce' );
$translate_plugin .= "{$here}";
$translate_plugin .= $external_icon;
$markup = << __( 'LPAC General Settings', 'lpac' ),
+ 'name' => __( 'LPAC General Settings', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_general_settings',
'type' => 'title',
'desc' => $this->lpac_create_plugin_settings_banner(),
@@ -146,9 +148,9 @@ public function lpac_create_general_setting_fields()
if ( empty($plugin_enabled) ) {
$lpac_settings[] = array(
- 'name' => __( 'Enabled', 'lpac' ),
- 'desc' => __( 'Yes', 'lpac' ),
- 'desc_tip' => __( 'Enable map on checkout and order details pages.', 'lpac' ),
+ 'name' => __( 'Enabled', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc' => __( 'Yes', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Enable map on checkout and order details pages.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_enabled',
'type' => 'checkbox',
'css' => 'max-width:80px;',
@@ -156,9 +158,9 @@ public function lpac_create_general_setting_fields()
);
} else {
$lpac_settings[] = array(
- 'name' => __( 'Enabled', 'lpac' ),
- 'desc' => __( 'Yes', 'lpac' ),
- 'desc_tip' => __( 'Enable map on checkout and order details pages.', 'lpac' ),
+ 'name' => __( 'Enabled', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc' => __( 'Yes', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Enable map on checkout and order details pages.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_enabled',
'type' => 'checkbox',
'css' => 'max-width:80px;',
@@ -166,34 +168,34 @@ public function lpac_create_general_setting_fields()
}
$lpac_settings[] = array(
- 'name' => __( 'Google Maps API Key', 'lpac' ),
- 'desc_tip' => __( 'Enter the API key from Google cloud console.', 'lpac' ),
- 'desc' => __( 'Enter the API key you copied from the Google Cloud Console. Learn More ', 'lpac' ),
+ 'name' => __( 'Google Maps API Key', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Enter the API key from Google cloud console.', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc' => __( 'Enter the API key you copied from the Google Cloud Console. Learn More ', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_google_maps_api_key',
'type' => 'text',
'css' => 'min-width:300px;',
);
$lpac_settings[] = array(
- 'name' => __( 'Force Use of Map', 'lpac' ),
- 'desc' => __( 'Yes', 'lpac' ),
- 'desc_tip' => __( 'Prevent the customer from checking out until they select a location on the map.', 'lpac' ),
+ 'name' => __( 'Force Use of Map', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc' => __( 'Yes', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Prevent the customer from checking out until they select a location on the map.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_force_map_use',
'type' => 'checkbox',
'css' => 'max-width:80px;',
);
$lpac_settings[] = array(
- 'name' => __( 'Default Coordinates', 'lpac' ),
- 'desc_tip' => __( 'Enter the default latitude and logitude that will be fetched every time the map loads.', 'lpac' ),
- 'desc' => __( 'Enter the default latitude and logitude that will be fetched every time the map loads. You can find the coordinates for a location here >>. Be sure to include the comma when adding your coordinates above.', 'lpac' ),
+ 'name' => __( 'Default Coordinates', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Enter the default latitude and logitude that will be fetched every time the map loads.', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc' => __( 'Enter the default latitude and logitude that will be fetched every time the map loads. You can find the coordinates for a location here >>. Be sure to include the comma when adding your coordinates above.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_map_starting_coordinates',
'placeholder' => '14.024519,-60.974876',
'type' => 'text',
'css' => 'min-width:300px;',
);
$lpac_settings[] = array(
- 'name' => __( 'Default Zoom', 'lpac' ),
- 'desc_tip' => __( 'Recommended number is 16.', 'lpac' ),
- 'desc' => __( 'Enter the default zoom that will be used every time the map loads.', 'lpac' ),
+ 'name' => __( 'Default Zoom', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Recommended number is 16.', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc' => __( 'Enter the default zoom that will be used every time the map loads.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_general_map_zoom_level',
'placeholder' => '16',
'default' => 3,
@@ -201,104 +203,104 @@ public function lpac_create_general_setting_fields()
'css' => 'max-width:80px;',
);
$lpac_settings[] = array(
- 'name' => __( 'Enable Clickable Icons', 'lpac' ),
- 'desc_tip' => __( 'Should customers be able to click on icons of different locations that appear on Google Maps? Recommended setting: Disabled', 'lpac' ),
- 'desc' => __( 'Yes', 'lpac' ),
+ 'name' => __( 'Enable Clickable Icons', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Should customers be able to click on icons of different locations that appear on Google Maps? Recommended setting: Disabled', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc' => __( 'Yes', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_allow_clicking_on_map_icons',
'type' => 'checkbox',
'css' => 'min-width:300px;',
);
$lpac_settings[] = array(
- 'name' => __( 'Autofill Billing fields', 'lpac' ),
- 'desc_tip' => __( 'Should the billing fields be automatically populated with information pulled from the location?', 'lpac' ),
- 'desc' => __( 'Yes', 'lpac' ),
+ 'name' => __( 'Autofill Billing fields', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Should the billing fields be automatically populated with information pulled from the location?', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc' => __( 'Yes', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_autofill_billing_fields',
'type' => 'checkbox',
'css' => 'min-width:300px;',
);
$lpac_settings[] = array(
- 'name' => __( 'Show Map on the Order Received Page', 'lpac' ),
- 'desc_tip' => __( 'This option displays a map view on the order received page after an order has been placed by a customer.', 'lpac' ),
+ 'name' => __( 'Show Map on the Order Received Page', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'This option displays a map view on the order received page after an order has been placed by a customer.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_display_map_on_order_received_page',
'type' => 'checkbox',
'css' => 'min-width:300px;',
- 'desc' => __( 'Enable', 'lpac' ),
+ 'desc' => __( 'Enable', 'map-location-picker-at-checkout-for-woocommerce' ),
);
$lpac_settings[] = array(
- 'name' => __( 'Show Map on View Order Page', 'lpac' ),
- 'desc_tip' => __( 'This option displays a map view on the order details page in the customer account.', 'lpac' ),
+ 'name' => __( 'Show Map on View Order Page', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'This option displays a map view on the order details page in the customer account.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_display_map_on_view_order_page',
'type' => 'checkbox',
'css' => 'min-width:300px;',
- 'desc' => __( 'Enable', 'lpac' ),
+ 'desc' => __( 'Enable', 'map-location-picker-at-checkout-for-woocommerce' ),
);
$lpac_settings[] = array(
- 'name' => __( 'Add Map Link to Order Emails?', 'lpac' ),
- 'desc_tip' => __( 'Add either a Button or QR Code that links to Google Maps to the order emails.', 'lpac' ),
+ 'name' => __( 'Add Map Link to Order Emails?', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Add either a Button or QR Code that links to Google Maps to the order emails.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_enable_delivery_map_link_in_email',
- 'desc' => __( 'Yes', 'lpac' ),
+ 'desc' => __( 'Yes', 'map-location-picker-at-checkout-for-woocommerce' ),
'type' => 'checkbox',
);
$lpac_settings[] = array(
- 'name' => __( 'Link Type', 'lpac' ),
- 'desc_tip' => __( 'Add either a button to Google Maps or a QR Code to the order emails.', 'lpac' ),
- 'desc' => __( 'QR Codes are saved to your uploads directory at: /wp-content/uploads/lpac-qr-codes/year/month/day/order_id.jpg
', 'lpac' ),
+ 'name' => __( 'Link Type', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Add either a button to Google Maps or a QR Code to the order emails.', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc' => __( 'QR Codes are saved to your uploads directory at: /wp-content/uploads/lpac-qr-codes/year/month/day/order_id.jpg
', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_email_delivery_map_link_type',
'type' => 'select',
'options' => array(
- 'button' => __( 'Button', 'lpac' ),
- 'qr_code' => __( 'QR Code', 'lpac' ),
+ 'button' => __( 'Button', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'qr_code' => __( 'QR Code', 'map-location-picker-at-checkout-for-woocommerce' ),
),
'css' => 'min-width:300px;',
);
$lpac_settings[] = array(
- 'name' => __( 'Link Location', 'lpac' ),
+ 'name' => __( 'Link Location', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_email_delivery_map_link_location',
'type' => 'select',
'options' => array(
- 'woocommerce_email_before_order_table' => __( 'Before Order Table', 'lpac' ),
- 'woocommerce_email_customer_details' => __( 'Before Customer Details', 'lpac' ),
+ 'woocommerce_email_before_order_table' => __( 'Before Order Table', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'woocommerce_email_customer_details' => __( 'Before Customer Details', 'map-location-picker-at-checkout-for-woocommerce' ),
),
'css' => 'min-width:300px;',
);
$lpac_settings[] = array(
- 'name' => __( 'Select Emails', 'lpac' ),
+ 'name' => __( 'Select Emails', 'map-location-picker-at-checkout-for-woocommerce' ),
'class' => 'wc-enhanced-select',
- 'desc' => __( 'Select the Emails you\'d like this setting to take effect on.', 'lpac' ),
+ 'desc' => __( 'Select the Emails you\'d like this setting to take effect on.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_email_delivery_map_emails',
'type' => 'multiselect',
'options' => array(
- 'new_order' => __( 'New Order', 'lpac' ),
- 'customer_on_hold_order' => __( 'Order on Hold', 'lpac' ),
- 'customer_note' => __( 'Customer Note', 'lpac' ),
- 'customer_completed_order' => __( 'Completed Order', 'lpac' ),
- 'customer_invoice' => __( 'Customer Invoice', 'lpac' ),
+ 'new_order' => __( 'New Order', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'customer_on_hold_order' => __( 'Order on Hold', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'customer_note' => __( 'Customer Note', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'customer_completed_order' => __( 'Completed Order', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'customer_invoice' => __( 'Customer Invoice', 'map-location-picker-at-checkout-for-woocommerce' ),
),
'css' => 'min-width:300px;height: 100px',
);
$lpac_settings[] = array(
- 'name' => __( 'Hide Map for Shipping Methods', 'lpac' ),
+ 'name' => __( 'Hide Map for Shipping Methods', 'map-location-picker-at-checkout-for-woocommerce' ),
'class' => 'wc-enhanced-select',
- 'desc' => __( 'Hide the map when any of these shipping methods are chosen by the user.', 'lpac' ),
+ 'desc' => __( 'Hide the map when any of these shipping methods are chosen by the user.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_wc_shipping_methods',
'type' => 'multiselect',
- 'options' => Lpac_Functions_Helper::lpac_get_available_shipping_methods(),
+ 'options' => Functions_Helper::lpac_get_available_shipping_methods(),
'css' => 'min-width:300px;height: 100px',
);
$lpac_settings[] = array(
- 'name' => __( 'Shipping Classes', 'lpac' ),
+ 'name' => __( 'Shipping Classes', 'map-location-picker-at-checkout-for-woocommerce' ),
'class' => 'wc-enhanced-select',
- 'desc' => __( 'Select shipping classes. NOTE: These settings apply if ANY of the items in the cart meets the condition.', 'lpac' ),
+ 'desc' => __( 'Select shipping classes. NOTE: These settings apply if ANY of the items in the cart meets the condition.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_wc_shipping_classes',
'type' => 'multiselect',
- 'options' => Lpac_Functions_Helper::lpac_get_available_shipping_classes(),
+ 'options' => Functions_Helper::lpac_get_available_shipping_classes(),
'css' => 'min-width:300px;height: 100px',
);
$lpac_settings[] = array(
- 'name' => __( 'Show or Hide', 'lpac' ),
+ 'name' => __( 'Show or Hide', 'map-location-picker-at-checkout-for-woocommerce' ),
'desc' => sprintf(
/* translators: 1: Line break HTML 2: opening strong tag 3: closing strong tag*/
- __( 'Should the map be shown or hidden if the order falls within above selected shipping classes? %1$s%1$s Selecting %2$sShow%3$s will display the map %2$sONLY IF%3$s the customer order falls inside the shipping classes selected above. %1$s Selecting %2$sHide%3$s will display the map only if the customer order %2$sDOES NOT%3$s fall inside the shipping classes selected above.', 'lpac' ),
+ __( 'Should the map be shown or hidden if the order falls within above selected shipping classes? %1$s%1$s Selecting %2$sShow%3$s will display the map %2$sONLY IF%3$s the customer order falls inside the shipping classes selected above. %1$s Selecting %2$sHide%3$s will display the map only if the customer order %2$sDOES NOT%3$s fall inside the shipping classes selected above.', 'map-location-picker-at-checkout-for-woocommerce' ),
'
',
'',
''
@@ -306,13 +308,13 @@ public function lpac_create_general_setting_fields()
'id' => 'lpac_wc_shipping_classes_show_hide',
'type' => 'radio',
'options' => array(
- 'show' => __( 'Show', 'lpac' ),
- 'hide' => __( 'Hide', 'lpac' ),
+ 'show' => __( 'Show', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'hide' => __( 'Hide', 'map-location-picker-at-checkout-for-woocommerce' ),
),
);
$lpac_settings[] = array(
- 'name' => __( 'Housekeeping', 'lpac' ),
- 'desc_tip' => __( 'Delete all plugin settings on uninstall.', 'lpac' ),
+ 'name' => __( 'Housekeeping', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Delete all plugin settings on uninstall.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_delete_settings_on_uninstall',
'type' => 'checkbox',
);
@@ -332,14 +334,14 @@ private function lpac_create_display_setting_fields()
{
$lpac_settings = array();
$lpac_settings[] = array(
- 'name' => __( 'LPAC Display Settings', 'lpac' ),
+ 'name' => __( 'LPAC Display Settings', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_display_settings',
'type' => 'title',
'desc' => $this->lpac_create_plugin_settings_banner(),
);
$lpac_settings[] = array(
- 'name' => __( 'Background Color (HEX)', 'lpac' ),
- 'desc' => __( 'Background color of map container (visible while map is loading).', 'lpac' ),
+ 'name' => __( 'Background Color (HEX)', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc' => __( 'Background color of map container (visible while map is loading).', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_map_background_color',
'type' => 'color',
'placeholder' => '#eeeeee',
@@ -347,21 +349,21 @@ private function lpac_create_display_setting_fields()
'css' => 'max-width:80px;',
);
$lpac_settings[] = array(
- 'name' => __( 'Where Should the Map Appear on the Checkout Page?', 'lpac' ),
- 'desc_tip' => __( 'This option displays a map view on the order received page after an order has been placed by a customer.', 'lpac' ),
+ 'name' => __( 'Where Should the Map Appear on the Checkout Page?', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'This option displays a map view on the order received page after an order has been placed by a customer.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_checkout_map_orientation',
'type' => 'select',
'options' => array(
- 'woocommerce_before_checkout_shipping_form' => __( 'Shipping Address Area - Top', 'lpac' ),
- 'woocommerce_after_checkout_shipping_form' => __( 'Shipping Address Area - Bottom (recommended)', 'lpac' ),
- 'woocommerce_before_checkout_billing_form' => __( 'Billing Address Area - Top', 'lpac' ),
- 'woocommerce_after_checkout_billing_form' => __( 'Billing Address Area - Bottom', 'lpac' ),
+ 'woocommerce_before_checkout_billing_form' => __( 'Billing Address Area - Top', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'woocommerce_after_checkout_billing_form' => __( 'Billing Address Area - Bottom', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'woocommerce_before_checkout_shipping_form' => __( 'Shipping Address Area - Top', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'woocommerce_after_checkout_shipping_form' => __( 'Shipping Address Area - Bottom', 'map-location-picker-at-checkout-for-woocommerce' ),
),
'css' => 'min-width:300px;',
);
$lpac_settings[] = array(
- 'name' => __( 'Checkout Page Map Width (in %)', 'lpac' ),
- 'desc_tip' => __( 'Enter the width of map you\'d like.', 'lpac' ),
+ 'name' => __( 'Checkout Page Map Width (in %)', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Enter the width of map you\'d like.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_checkout_page_map_width',
'placeholder' => '100',
'default' => 100,
@@ -369,8 +371,8 @@ private function lpac_create_display_setting_fields()
'css' => 'max-width:80px;',
);
$lpac_settings[] = array(
- 'name' => __( 'Checkout Page Map Height (in px)', 'lpac' ),
- 'desc_tip' => __( 'Enter the height of map you\'d like.', 'lpac' ),
+ 'name' => __( 'Checkout Page Map Height (in px)', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Enter the height of map you\'d like.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_checkout_page_map_height',
'placeholder' => '400',
'default' => 400,
@@ -378,8 +380,8 @@ private function lpac_create_display_setting_fields()
'css' => 'max-width:80px;',
);
$lpac_settings[] = array(
- 'name' => __( 'Order Received Page Map Height (in px)', 'lpac' ),
- 'desc_tip' => __( 'Enter the height of map you\'d like.', 'lpac' ),
+ 'name' => __( 'Order Received Page Map Height (in px)', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Enter the height of map you\'d like.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_order_received_page_map_height',
'placeholder' => '400',
'default' => 400,
@@ -387,8 +389,8 @@ private function lpac_create_display_setting_fields()
'css' => 'max-width:80px;',
);
$lpac_settings[] = array(
- 'name' => __( 'Order Received Page Map Width (in px)', 'lpac' ),
- 'desc_tip' => __( 'Enter the width of map you\'d like.', 'lpac' ),
+ 'name' => __( 'Order Received Page Map Width (in px)', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Enter the width of map you\'d like.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_order_received_page_map_width',
'placeholder' => '100',
'default' => 100,
@@ -396,8 +398,8 @@ private function lpac_create_display_setting_fields()
'css' => 'max-width:80px;',
);
$lpac_settings[] = array(
- 'name' => __( 'View Order Page Map Height (in px)', 'lpac' ),
- 'desc_tip' => __( 'Enter the height of map you\'d like.', 'lpac' ),
+ 'name' => __( 'View Order Page Map Height (in px)', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Enter the height of map you\'d like.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_view_order_page_map_height',
'placeholder' => '400',
'default' => 400,
@@ -405,8 +407,8 @@ private function lpac_create_display_setting_fields()
'css' => 'max-width:80px;',
);
$lpac_settings[] = array(
- 'name' => __( 'View Order Page Map Width (in px)', 'lpac' ),
- 'desc_tip' => __( 'Enter the height of map you\'d like.', 'lpac' ),
+ 'name' => __( 'View Order Page Map Width (in px)', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Enter the height of map you\'d like.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_view_order_page_map_width',
'placeholder' => '100',
'default' => 100,
@@ -429,19 +431,31 @@ private function lpac_create_debug_setting_fields()
{
$lpac_settings = array();
$lpac_settings[] = array(
- 'name' => __( 'LPAC Debug Settings', 'lpac' ),
+ 'name' => __( 'LPAC Debug Settings', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_debug_settings',
'type' => 'title',
'desc' => $this->lpac_create_plugin_settings_banner(),
);
$lpac_settings[] = array(
- 'name' => __( 'Hide checkout notice', 'lpac' ),
- 'desc' => __( 'Yes', 'lpac' ),
- 'desc_tip' => __( 'Hide the admin checkout notice.', 'lpac' ),
+ 'name' => __( 'Hide checkout notice', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc' => __( 'Yes', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc_tip' => __( 'Hide the admin checkout notice.', 'map-location-picker-at-checkout-for-woocommerce' ),
'id' => 'lpac_hide_troubleshooting_admin_checkout_notice',
'type' => 'checkbox',
'css' => 'max-width:80px;',
);
+ $lpac_settings[] = array(
+ 'name' => __( 'Dequeue Google Maps Script in Frontend', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'desc' => __( 'If you\'re receiving console errors about Google Maps already being loaded by another plugin, then select where the Google Maps script should be removed. Be sure to test the map if you turn this option on.', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'id' => 'lpac_dequeue_google_maps',
+ 'type' => 'radio',
+ 'options' => array(
+ 'none' => __( 'None', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'frontend' => __( 'Frontend', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'dashboard' => __( 'Dashboard', 'map-location-picker-at-checkout-for-woocommerce' ),
+ 'both' => __( 'Both', 'map-location-picker-at-checkout-for-woocommerce' ),
+ ),
+ );
$lpac_settings[] = array(
'type' => 'sectionend',
'id' => 'lpac_debug_settings_section_end',
@@ -474,8 +488,8 @@ public function lpac_create_plugin_settings_fields()
// Custom attributes example
// https://woocommerce.github.io/code-reference/files/woocommerce-includes-admin-wc-meta-box-functions.html#source-view.146
// $lpac_settings[] = array(
- // 'name' => __( 'Test', 'lpac' ),
- // 'desc_tip' => __( 'Delete all plugin settings on uninstall.', 'lpac' ),
+ // 'name' => __( 'Test', 'map-location-picker-at-checkout-for-woocommerce' ),
+ // 'desc_tip' => __( 'Delete all plugin settings on uninstall.', 'map-location-picker-at-checkout-for-woocommerce' ),
// 'id' => 'lpac_delete_settings_on_uninstall',
// 'type' => 'text',
// 'custom_attributes' => array(
@@ -495,7 +509,7 @@ public function lpac_create_plugin_settings_fields()
public function lpac_output_plugin_settings()
{
$settings = $this->lpac_create_plugin_settings_fields();
- WC_Admin_Settings::output_fields( $settings );
+ \WC_Admin_Settings::output_fields( $settings );
}
/**
@@ -506,11 +520,10 @@ public function lpac_save_plugin_settings()
{
global $current_section ;
$settings = $this->lpac_create_plugin_settings_fields();
- WC_Admin_Settings::save_fields( $settings );
+ \WC_Admin_Settings::save_fields( $settings );
if ( $current_section ) {
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
}
}
-}
-new Lpac_Admin_Settings();
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/includes/public/class-lpac-public-display.php b/includes/Views/Frontend.php
similarity index 69%
rename from includes/public/class-lpac-public-display.php
rename to includes/Views/Frontend.php
index 845716e..caab73d 100644
--- a/includes/public/class-lpac-public-display.php
+++ b/includes/Views/Frontend.php
@@ -9,9 +9,12 @@
* @since 1.0.0
*
* @package Lpac
- * @subpackage Lpac/public/partials
*/
-class Lpac_Public_Display extends Lpac_Public {
+namespace Lpac\Views;
+
+use Lpac\Helpers\Functions as Functions_Helper;
+
+class Frontend {
/**
* Global map settings for JavaScript.
@@ -32,6 +35,64 @@ public function __construct() {
$this->lpac_expose_map_settings_js();
}
+ /**
+ * Map settings.
+ *
+ * @since 1.0.0
+ */
+ public function lpac_get_map_settings() {
+
+ $starting_coordinates = get_option( 'lpac_map_starting_coordinates', '14.024519,-60.974876' );
+ $starting_coordinates = apply_filters( 'lpac_map_starting_coordinates', $starting_coordinates );
+
+ $coordinates_parts = explode( ',', $starting_coordinates );
+ $latitude = ! empty( $coordinates_parts[0] ) ? (float) $coordinates_parts[0] : (float) 14.024519;
+ $longitude = ! empty( $coordinates_parts[1] ) ? (float) $coordinates_parts[1] : (float) -60.974876;
+
+ $zoom_level = (int) get_option( 'lpac_general_map_zoom_level', 16 );
+ $zoom_level = apply_filters( 'lpac_general_map_zoom_level', $zoom_level );
+
+ $clickable_icons = get_option( 'lpac_allow_clicking_on_map_icons', 'yes' );
+ $clickable_icons = apply_filters( 'lpac_allow_clicking_on_map_icons', $clickable_icons );
+
+ $background_color = get_option( 'lpac_map_background_color', '#eee' );
+ $background_color = apply_filters( 'lpac_map_background_color', $background_color );
+
+ $fill_in_billing_fields = get_option( 'lpac_autofill_billing_fields', 'yes' );
+ $fill_in_billing_fields = apply_filters( 'lpac_autofill_billing_fields', $fill_in_billing_fields );
+
+ $data = array(
+ 'lpac_map_default_latitude' => $latitude,
+ 'lpac_map_default_longitude' => $longitude,
+ 'lpac_map_zoom_level' => $zoom_level,
+ 'lpac_map_clickable_icons' => $clickable_icons === 'yes' ? true : false,
+ 'lpac_map_background_color' => $background_color,
+ 'lpac_autofill_billing_fields' => $fill_in_billing_fields === 'yes' ? true : false,
+
+ );
+
+ return apply_filters( 'lpac_map_stored_settings', $data );
+
+ }
+
+ /**
+ * Detect needed Woocommerce pages.
+ *
+ * Detect if the page is one of which the map is supposed to show.
+ *
+ * @since 1.1.0
+ *
+ * @return bool Whether or not the page is one of our needed pages.
+ */
+ public function lpac_is_allowed_woocommerce_pages() {
+
+ if ( is_wc_endpoint_url( 'view-order' ) || is_wc_endpoint_url( 'order-received' ) || is_checkout() ) {
+ return true;
+ }
+
+ return false;
+ }
+
/**
* Exposes map settings to be used in client-side javascript.
*
@@ -68,14 +129,14 @@ private function lpac_expose_map_settings_js( $additional = array() ) {
*/
public function lpac_output_map_on_checkout_page() {
- if ( Lpac_Functions_Helper::lpac_show_map( 'checkout' ) === false ) {
+ if ( Functions_Helper::lpac_show_map( 'checkout' ) === false ) {
return;
}
- $btn_text = __( 'Detect Current Location', 'lpac' );
+ $btn_text = __( 'Detect Current Location', 'map-location-picker-at-checkout-for-woocommerce' );
$lpac_find_location_btn_text = apply_filters( 'lpac_find_location_btn_text', $btn_text );
- $instuctions_text = __( 'Click the "Detect Current Location" button then move the red marker to your desired shipping address.', 'lpac' );
+ $instuctions_text = __( 'Click the "Detect Current Location" button then move the red marker to your desired shipping address.', 'map-location-picker-at-checkout-for-woocommerce' );
$instuctions_text = apply_filters( 'lpac_map_instuctions_text', $instuctions_text );
$user_id = (int) get_current_user_id();
@@ -92,6 +153,7 @@ public function lpac_output_map_on_checkout_page() {
$before_map_controls_filter = apply_filters( 'lpac_before_map_controls', '', $user_id );
$before_map_controls_filter = wp_kses_post( $before_map_controls_filter );
+ // TODO use this filter to create our saved address field
$after_map_controls_filter = apply_filters( 'lpac_after_map_controls', '', $user_id );
$after_map_controls_filter = wp_kses_post( $after_map_controls_filter );
@@ -102,8 +164,8 @@ public function lpac_output_map_on_checkout_page() {
$after_map_filter
$before_map_controls_filter
-
$instuctions_text
-
+
$instuctions_text
+
$after_map_controls_filter
@@ -131,8 +193,8 @@ public function lpac_output_map_on_order_details_page() {
return;
}
- $show_on_view_order_page = Lpac_Functions_Helper::lpac_show_map( 'lpac_display_map_on_view_order_page' );
- $show_on_order_received_page = Lpac_Functions_Helper::lpac_show_map( 'lpac_display_map_on_order_received_page' );
+ $show_on_view_order_page = Functions_Helper::lpac_show_map( 'lpac_display_map_on_view_order_page' );
+ $show_on_order_received_page = Functions_Helper::lpac_show_map( 'lpac_display_map_on_order_received_page' );
if ( is_wc_endpoint_url( 'view-order' ) && $show_on_view_order_page === false ) {
return;
@@ -154,16 +216,20 @@ public function lpac_output_map_on_order_details_page() {
return;
}
- $latitude = (float) get_post_meta( $order_id, '_lpac_latitude', true );
- $longitude = (float) get_post_meta( $order_id, '_lpac_longitude', true );
+ $latitude = (float) get_post_meta( $order_id, '_lpac_latitude', true );
+ $longitude = (float) get_post_meta( $order_id, '_lpac_longitude', true );
+ $shipping_address_1 = get_post_meta( $order_id, '_shipping_address_1', true );
+ $shipping_address_2 = get_post_meta( $order_id, '_shipping_address_2', true );
if ( empty( $latitude ) || empty( $longitude ) ) {
return;
}
$user_location_collected_during_order = array(
- 'lpac_map_order_latitude' => $latitude,
- 'lpac_map_order_longitude' => $longitude,
+ 'lpac_map_order_latitude' => $latitude,
+ 'lpac_map_order_longitude' => $longitude,
+ 'lpac_map_order_shipping_address_1' => $shipping_address_1,
+ 'lpac_map_order_shipping_address_2' => $shipping_address_2,
);
$this->lpac_expose_map_settings_js( $user_location_collected_during_order );
@@ -190,21 +256,21 @@ public function lpac_output_map_on_order_details_page() {
public function lpac_create_lat_and_long_inputs( $fields ) {
$fields['billing']['lpac_latitude'] = array(
- 'label' => __( 'Latitude', 'lpac' ),
+ 'label' => __( 'Latitude', 'map-location-picker-at-checkout-for-woocommerce' ),
'required' => false,
- 'class' => array( 'form-row-wide', 'hidden' ),
+ 'class' => ( LPAC_DEBUG ) ? array( 'form-row-wide' ) : array( 'form-row-wide', 'hidden' ),
);
$fields['billing']['lpac_longitude'] = array(
- 'label' => __( 'Longitude', 'lpac' ),
+ 'label' => __( 'Longitude', 'map-location-picker-at-checkout-for-woocommerce' ),
'required' => false,
- 'class' => array( 'form-row-wide', 'hidden' ),
+ 'class' => ( LPAC_DEBUG ) ? array( 'form-row-wide' ) : array( 'form-row-wide', 'hidden' ),
);
$fields['billing']['lpac_is_map_shown'] = array(
- 'label' => __( 'Map Shown', 'lpac' ),
+ 'label' => __( 'Map Shown', 'map-location-picker-at-checkout-for-woocommerce' ),
'required' => false,
- 'class' => array( 'form-row-wide', 'hidden' ),
+ 'class' => ( LPAC_DEBUG ) ? array( 'form-row-wide' ) : array( 'form-row-wide', 'hidden' ),
);
return $fields;
@@ -239,7 +305,7 @@ public function lpac_validate_location_fields( $fields, $errors ) {
return;
}
- $error_msg = '' . __( 'Please select your location using the Google Map.', 'lpac' ) . '';
+ $error_msg = '' . __( 'Please select your location using the Google Map.', 'map-location-picker-at-checkout-for-woocommerce' ) . '';
$error_msg = apply_filters( 'lpac_checkout_empty_cords_error_msg', $error_msg );
@@ -256,7 +322,7 @@ public function lpac_validate_location_fields( $fields, $errors ) {
* @param array $order_id The order id.
*/
public function lpac_save_cords_order_meta( $order_id ) {
-
+ //TODO move to model class
$latitude = $_POST['lpac_latitude'] ?? '';
$longitude = $_POST['lpac_longitude'] ?? '';
$map_shown = $_POST['lpac_is_map_shown'] ?? '';
@@ -324,80 +390,10 @@ public function lpac_output_map_custom_styles() {
}
/**
- * Create map location button link in email.
+ * Show a notice banner to admins on the frontend.
*
- * @param string $link The link to google maps.
- * @since 1.1.0
- */
- public function lpac_create_delivery_location_link_button( $link ) {
-
- $button_text = __( 'Delivery Location', 'lpac' );
- $button_text = apply_filters( 'lpac_map_location_link_button_text', $button_text );
- $base_color = get_option( 'woocommerce_email_base_color' );
- $text_color = wc_light_or_dark( $base_color, '#202020', '#ffffff' );
-
- $button = <<