Changeset 3807488
- Timestamp:
- 11/17/2026 01:28:28 PM (less than one hour ago)
- Location:
- posturinn
- Files:
-
- 2 deleted
- 12 edited
- 1 copied
-
tags/1.5.2 (copied) (copied from posturinn/trunk )
-
tags/1.5.2/CLAUDE.md (deleted)
-
tags/1.5.2/inc/hooks.php (modified) (4 diffs)
-
tags/1.5.2/inc_hpos/admin.class.php (modified) (1 diff)
-
tags/1.5.2/inc_hpos/hooks.php (modified) (4 diffs)
-
tags/1.5.2/js/postis-googlemap.js (modified) (6 diffs)
-
tags/1.5.2/readme.txt (modified) (3 diffs)
-
tags/1.5.2/wc-posturinn-shipping-api.php (modified) (2 diffs)
-
trunk/CLAUDE.md (deleted)
-
trunk/inc/hooks.php (modified) (4 diffs)
-
trunk/inc_hpos/admin.class.php (modified) (1 diff)
-
trunk/inc_hpos/hooks.php (modified) (4 diffs)
-
trunk/js/postis-googlemap.js (modified) (6 diffs)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/wc-posturinn-shipping-api.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
posturinn/tags/1.5.2/inc/hooks.php
r3570342 r3807488 72 72 wp_enqueue_script('postis-remodal', POSTIS_URL."/js/remodal.js", array('jquery'), '1.1.3', true); 73 73 74 wp_enqueue_script('postis-gm-js', POSTIS_URL."/js/postis-googlemap.js", array('jquery'), '1.1.3', true); 75 } 76 } 77 } 78 79 80 /** 81 * Render Extra Content After Checkout Form (Google Map) 82 **/ 83 function postis_hooks_after_checkout_form(){ 84 74 wp_enqueue_script('postis-gm-js', POSTIS_URL."/js/postis-googlemap.js", array('jquery'), postis_get_plugin_version(), true); 75 } 76 } 77 } 78 79 80 /** 81 * Build the Google Map postbox list (also refreshed through checkout fragments) 82 **/ 83 function postis_get_googlemap_locations_html(){ 84 85 $empty_list = '<ul class="postis-googlemap-locations"></ul>'; 86 87 if ( ! WC()->session ) { 88 return $empty_list; 89 } 90 85 91 // Get the exact same postbox services that the dropdown uses 86 92 $postbox_services = WC()->session->get('postis_postbox_services', array()); 87 88 if (!empty($postbox_services)) { 89 90 // We have the same data as the dropdown, now we need to get coordinates 91 // We'll need to call the postboxes API to get lat/lng for each service 92 $postboxes_with_coords = array(); 93 94 // Get postboxes API data for coordinates 93 94 if (empty($postbox_services)) { 95 return $empty_list; 96 } 97 98 // Only DPO/DNO services are postboxes 99 $postbox_service_list = array(); 100 foreach ($postbox_services as $service) { 101 $base_service_id = substr($service['deliveryServiceId'], 0, 3); 102 if ($base_service_id === 'DPO' || $base_service_id === 'DNO') { 103 $postbox_service_list[] = $service; 104 } 105 } 106 107 if (empty($postbox_service_list)) { 108 return $empty_list; 109 } 110 111 // Coordinates come from the postboxes API; cached because this runs on every checkout refresh 112 $postboxes_api_data = get_transient('postis_postboxes_coords'); 113 114 if (empty($postboxes_api_data) || !is_array($postboxes_api_data)) { 115 $postboxes_api_data = array(); 116 95 117 $endpoint_url = postis_get_endpoints('postboxes'); 96 118 $postis_apikey = postis_get_api_key(); 97 119 $domain = postis_get_homeurl(); 98 120 99 121 $req_headers = array( 100 122 "headers" => array( 101 'x-api-key' => $postis_apikey, 123 'x-api-key' => $postis_apikey, 102 124 'domain_name' => $domain, 103 125 'user-agent' => 'WooCommerce/'.postis_get_woocommerce_version().' | Postis/'.postis_get_plugin_version(), … … 106 128 ) 107 129 ); 108 130 109 131 $response = wp_remote_get($endpoint_url, $req_headers); 110 $postboxes_api_data = array(); 111 112 if (!is_wp_error($response) && $response['response']['code'] == 200) { 132 133 if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) == 200) { 113 134 $postboxes_response = json_decode(wp_remote_retrieve_body($response), true); 114 115 if ( isset($postboxes_response['postboxes'])) {135 136 if (!empty($postboxes_response['postboxes'])) { 116 137 // Index by postbox ID for quick lookup 117 138 foreach ($postboxes_response['postboxes'] as $postbox) { 118 139 $postboxes_api_data[$postbox['postboxId']] = $postbox; 119 140 } 141 142 set_transient('postis_postboxes_coords', $postboxes_api_data, HOUR_IN_SECONDS); 120 143 } 121 144 } 122 123 // Now combine the session services with coordinates from API 124 foreach ($postbox_services as $service) { 125 $service_id = $service['deliveryServiceId']; 126 $base_service_id = substr($service_id, 0, 3); 127 128 if ($base_service_id === 'DPO' || $base_service_id === 'DNO') { 129 // Extract postbox ID (remove DPO/DNO prefix) 130 $postbox_id = substr($service_id, 3); 131 132 // Get coordinates from API data 133 $coords = isset($postboxes_api_data[$postbox_id]) ? $postboxes_api_data[$postbox_id] : array(); 134 135 $postboxes_with_coords[] = array( 136 'deliveryServiceId' => $service_id, // Full ID like DPO9556 137 'postboxId' => $postbox_id, 138 'name' => $service['nameLong'], 139 'postcode' => isset($coords['postcode']) ? $coords['postcode'] : '', 140 'address' => isset($coords['address']) ? $coords['address'] : '', 141 'town' => isset($coords['town']) ? $coords['town'] : '', 142 'latitude' => isset($coords['latitude']) ? $coords['latitude'] : '', 143 'longitude' => isset($coords['longitude']) ? $coords['longitude'] : '', 144 ); 145 } 146 } 147 148 if (!empty($postboxes_with_coords)) { 145 } 146 147 // Combine the session services with coordinates from API 148 $postboxes_with_coords = array(); 149 foreach ($postbox_service_list as $service) { 150 $service_id = $service['deliveryServiceId']; 151 // Extract postbox ID (remove DPO/DNO prefix) 152 $postbox_id = substr($service_id, 3); 153 154 $coords = isset($postboxes_api_data[$postbox_id]) ? $postboxes_api_data[$postbox_id] : array(); 155 156 $postboxes_with_coords[] = array( 157 'deliveryServiceId' => $service_id, // Full ID like DPO9556 158 'postboxId' => $postbox_id, 159 'name' => $service['nameLong'], 160 'postcode' => isset($coords['postcode']) ? $coords['postcode'] : '', 161 'address' => isset($coords['address']) ? $coords['address'] : '', 162 'town' => isset($coords['town']) ? $coords['town'] : '', 163 'latitude' => isset($coords['latitude']) ? $coords['latitude'] : '', 164 'longitude' => isset($coords['longitude']) ? $coords['longitude'] : '', 165 ); 166 } 167 168 ob_start(); 169 ?> 170 <ul class="postis-googlemap-locations"> 171 <?php 172 foreach ($postboxes_with_coords as $index => $meta) { 173 $postboxId = $meta['postboxId']; 174 $deliveryServiceId = $meta['deliveryServiceId']; 175 $postcode = $meta['postcode']; 176 $name = $meta['name']; 177 $latitude = $meta['latitude']; 178 $longitude = $meta['longitude']; 179 ?> 180 <li class="postis-googlemap-location" 181 data-postboxes="<?php echo esc_attr(json_encode($meta, JSON_FORCE_OBJECT)); ?>" 182 data-lat="<?php echo esc_attr($latitude); ?>" 183 data-long="<?php echo esc_attr($longitude); ?>" 184 data-postbox-id="<?php echo esc_attr($postboxId); ?>" 185 data-delivery-service-id="<?php echo esc_attr($deliveryServiceId); ?>"> 186 <span><?php echo esc_html($name); ?></span> 187 <span>(<?php echo esc_html($postcode); ?>)</span> 188 </li> 189 <?php 190 } 191 ?> 192 </ul> 193 <?php 194 return ob_get_clean(); 195 } 196 197 198 /** 199 * Render Extra Content After Checkout Form (Google Map) 200 **/ 201 function postis_hooks_after_checkout_form(){ 202 203 // Always render the dialog: it sits outside the parts WooCommerce refreshes, 204 // so the list inside is kept current through the checkout fragments instead. 149 205 ?> 150 206 <div data-remodal-id="postis_googlemap_modal" role="dialog"> … … 155 211 <div class="postis-col-wrapper"> 156 212 <div class="postis-postboxes-section"> 157 <ul> 158 <?php 159 foreach ($postboxes_with_coords as $index => $meta) { 160 $postboxId = $meta['postboxId']; 161 $deliveryServiceId = $meta['deliveryServiceId']; 162 $postcode = $meta['postcode']; 163 $name = $meta['name']; 164 $latitude = $meta['latitude']; 165 $longitude = $meta['longitude']; 166 ?> 167 <li class="postis-googlemap-location" 168 data-postboxes="<?php echo esc_attr(json_encode($meta, JSON_FORCE_OBJECT)); ?>" 169 data-lat="<?php echo esc_attr($latitude); ?>" 170 data-long="<?php echo esc_attr($longitude); ?>" 171 data-postbox-id="<?php echo esc_attr($postboxId); ?>" 172 data-delivery-service-id="<?php echo esc_attr($deliveryServiceId); ?>"> 173 <span><?php echo esc_html($name); ?></span> 174 <span>(<?php echo esc_html($postcode); ?>)</span> 175 </li> 176 <?php 177 } 178 ?> 179 </ul> 213 <?php echo postis_get_googlemap_locations_html(); ?> 180 214 <button data-remodal-action="confirm" class="postis-postbox-js remodal-confirm"><?php echo __("Choose Postbox", "postis"); ?></button> 181 215 </div> … … 187 221 </div> 188 222 <?php 189 } 190 } 191 } 223 } 224 225 226 /** 227 * Refresh the Google Map postbox list on checkout updates 228 **/ 229 function postis_hooks_googlemap_fragments( $fragments ){ 230 231 $fragments['ul.postis-googlemap-locations'] = postis_get_googlemap_locations_html(); 232 233 return $fragments; 234 } 235 236 237 /** 238 * Keep the customer's chosen Pósturinn service when the rates change 239 **/ 240 function postis_hooks_keep_chosen_shipping_service( $default, $rates, $chosen_method ){ 241 242 $pattern = '/^(postis:)?([A-Z]{3})[0-9]*$/'; 243 244 // Only act on our own rates (others look like local_pickup:1, flat_rate:3, free_shipping). 245 if ( ! is_string( $chosen_method ) || ! preg_match( $pattern, $chosen_method, $chosen_match ) ) { 246 return $default; 247 } 248 249 if ( ! is_array( $rates ) ) { 250 return $default; 251 } 252 253 // WooCommerce resets to the first rate whenever the rate list changes, and our 254 // rate IDs vary per postcode, so match on the service instead of the exact ID. 255 if ( isset( $rates[ $chosen_method ] ) ) { 256 return $chosen_method; 257 } 258 259 // DPH and DPL are both home delivery. 260 $same_service = array( 'DPL' => 'DPH' ); 261 $chosen_code = isset( $same_service[ $chosen_match[2] ] ) ? $same_service[ $chosen_match[2] ] : $chosen_match[2]; 262 263 foreach ( $rates as $rate_id => $rate ) { 264 if ( ! is_object( $rate ) || $rate->get_method_id() !== 'postis' || ! preg_match( $pattern, $rate_id, $rate_match ) ) { 265 continue; 266 } 267 268 $rate_code = isset( $same_service[ $rate_match[2] ] ) ? $same_service[ $rate_match[2] ] : $rate_match[2]; 269 270 if ( $rate_code === $chosen_code ) { 271 return $rate_id; 272 } 273 } 274 275 return $default; 276 } -
posturinn/tags/1.5.2/inc_hpos/admin.class.php
r3390272 r3807488 736 736 737 737 function bulk_admin_notices() { 738 global $post_type, $pagenow; 739 740 if ('edit.php' !== $pagenow || 'shop_order' !== $post_type || !isset($_REQUEST['bulk_action'])) { 738 $screen = function_exists('get_current_screen') ? get_current_screen() : null; 739 740 // With HPOS the orders list is admin.php?page=wc-orders, not edit.php?post_type=shop_order. 741 if (!$screen || wc_get_page_screen_id('shop-order') !== $screen->id || !isset($_REQUEST['bulk_action'])) { 741 742 return; 742 743 } -
posturinn/tags/1.5.2/inc_hpos/hooks.php
r3570342 r3807488 73 73 wp_enqueue_script('postis-remodal', POSTIS_URL."/js/remodal.js", array('jquery'), '1.1.3', true); 74 74 75 wp_enqueue_script('postis-gm-js', POSTIS_URL."/js/postis-googlemap.js", array('jquery'), '1.1.3', true); 76 } 77 } 78 } 79 80 81 /** 82 * Render Extra Content After Checkout Form (Google Map) 83 **/ 84 function postis_hooks_after_checkout_form(){ 85 75 wp_enqueue_script('postis-gm-js', POSTIS_URL."/js/postis-googlemap.js", array('jquery'), postis_get_plugin_version(), true); 76 } 77 } 78 } 79 80 81 /** 82 * Build the Google Map postbox list (also refreshed through checkout fragments) 83 **/ 84 function postis_get_googlemap_locations_html(){ 85 86 $empty_list = '<ul class="postis-googlemap-locations"></ul>'; 87 88 if ( ! WC()->session ) { 89 return $empty_list; 90 } 91 86 92 // Get the exact same postbox services that the dropdown uses 87 93 $postbox_services = WC()->session->get('postis_postbox_services', array()); 88 89 if (!empty($postbox_services)) { 90 91 // We have the same data as the dropdown, now we need to get coordinates 92 // We'll need to call the postboxes API to get lat/lng for each service 93 $postboxes_with_coords = array(); 94 95 // Get postboxes API data for coordinates 94 95 if (empty($postbox_services)) { 96 return $empty_list; 97 } 98 99 // Only DPO/DNO services are postboxes 100 $postbox_service_list = array(); 101 foreach ($postbox_services as $service) { 102 $base_service_id = substr($service['deliveryServiceId'], 0, 3); 103 if ($base_service_id === 'DPO' || $base_service_id === 'DNO') { 104 $postbox_service_list[] = $service; 105 } 106 } 107 108 if (empty($postbox_service_list)) { 109 return $empty_list; 110 } 111 112 // Coordinates come from the postboxes API; cached because this runs on every checkout refresh 113 $postboxes_api_data = get_transient('postis_postboxes_coords'); 114 115 if (empty($postboxes_api_data) || !is_array($postboxes_api_data)) { 116 $postboxes_api_data = array(); 117 96 118 $endpoint_url = postis_get_endpoints('postboxes'); 97 119 $postis_apikey = postis_get_api_key(); 98 120 $domain = postis_get_homeurl(); 99 121 100 122 $req_headers = array( 101 123 "headers" => array( 102 'x-api-key' => $postis_apikey, 124 'x-api-key' => $postis_apikey, 103 125 'domain_name' => $domain, 104 126 'user-agent' => 'WooCommerce/'.postis_get_woocommerce_version().' | Postis/'.postis_get_plugin_version(), … … 107 129 ) 108 130 ); 109 131 110 132 $response = wp_remote_get($endpoint_url, $req_headers); 111 $postboxes_api_data = array(); 112 113 if (!is_wp_error($response) && $response['response']['code'] == 200) { 133 134 if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) == 200) { 114 135 $postboxes_response = json_decode(wp_remote_retrieve_body($response), true); 115 116 if ( isset($postboxes_response['postboxes'])) {136 137 if (!empty($postboxes_response['postboxes'])) { 117 138 // Index by postbox ID for quick lookup 118 139 foreach ($postboxes_response['postboxes'] as $postbox) { 119 140 $postboxes_api_data[$postbox['postboxId']] = $postbox; 120 141 } 142 143 set_transient('postis_postboxes_coords', $postboxes_api_data, HOUR_IN_SECONDS); 121 144 } 122 145 } 123 124 // Now combine the session services with coordinates from API 125 foreach ($postbox_services as $service) { 126 $service_id = $service['deliveryServiceId']; 127 $base_service_id = substr($service_id, 0, 3); 128 129 if ($base_service_id === 'DPO' || $base_service_id === 'DNO') { 130 // Extract postbox ID (remove DPO/DNO prefix) 131 $postbox_id = substr($service_id, 3); 132 133 // Get coordinates from API data 134 $coords = isset($postboxes_api_data[$postbox_id]) ? $postboxes_api_data[$postbox_id] : array(); 135 136 $postboxes_with_coords[] = array( 137 'deliveryServiceId' => $service_id, // Full ID like DPO9556 138 'postboxId' => $postbox_id, 139 'name' => $service['nameLong'], 140 'postcode' => isset($coords['postcode']) ? $coords['postcode'] : '', 141 'address' => isset($coords['address']) ? $coords['address'] : '', 142 'town' => isset($coords['town']) ? $coords['town'] : '', 143 'latitude' => isset($coords['latitude']) ? $coords['latitude'] : '', 144 'longitude' => isset($coords['longitude']) ? $coords['longitude'] : '', 145 ); 146 } 147 } 148 149 if (!empty($postboxes_with_coords)) { 146 } 147 148 // Combine the session services with coordinates from API 149 $postboxes_with_coords = array(); 150 foreach ($postbox_service_list as $service) { 151 $service_id = $service['deliveryServiceId']; 152 // Extract postbox ID (remove DPO/DNO prefix) 153 $postbox_id = substr($service_id, 3); 154 155 $coords = isset($postboxes_api_data[$postbox_id]) ? $postboxes_api_data[$postbox_id] : array(); 156 157 $postboxes_with_coords[] = array( 158 'deliveryServiceId' => $service_id, // Full ID like DPO9556 159 'postboxId' => $postbox_id, 160 'name' => $service['nameLong'], 161 'postcode' => isset($coords['postcode']) ? $coords['postcode'] : '', 162 'address' => isset($coords['address']) ? $coords['address'] : '', 163 'town' => isset($coords['town']) ? $coords['town'] : '', 164 'latitude' => isset($coords['latitude']) ? $coords['latitude'] : '', 165 'longitude' => isset($coords['longitude']) ? $coords['longitude'] : '', 166 ); 167 } 168 169 ob_start(); 170 ?> 171 <ul class="postis-googlemap-locations"> 172 <?php 173 foreach ($postboxes_with_coords as $index => $meta) { 174 $postboxId = $meta['postboxId']; 175 $deliveryServiceId = $meta['deliveryServiceId']; 176 $postcode = $meta['postcode']; 177 $name = $meta['name']; 178 $latitude = $meta['latitude']; 179 $longitude = $meta['longitude']; 180 ?> 181 <li class="postis-googlemap-location" 182 data-postboxes="<?php echo esc_attr(json_encode($meta, JSON_FORCE_OBJECT)); ?>" 183 data-lat="<?php echo esc_attr($latitude); ?>" 184 data-long="<?php echo esc_attr($longitude); ?>" 185 data-postbox-id="<?php echo esc_attr($postboxId); ?>" 186 data-delivery-service-id="<?php echo esc_attr($deliveryServiceId); ?>"> 187 <span><?php echo esc_html($name); ?></span> 188 <span>(<?php echo esc_html($postcode); ?>)</span> 189 </li> 190 <?php 191 } 192 ?> 193 </ul> 194 <?php 195 return ob_get_clean(); 196 } 197 198 199 /** 200 * Render Extra Content After Checkout Form (Google Map) 201 **/ 202 function postis_hooks_after_checkout_form(){ 203 204 // Always render the dialog: it sits outside the parts WooCommerce refreshes, 205 // so the list inside is kept current through the checkout fragments instead. 150 206 ?> 151 207 <div data-remodal-id="postis_googlemap_modal" role="dialog"> … … 156 212 <div class="postis-col-wrapper"> 157 213 <div class="postis-postboxes-section"> 158 <ul> 159 <?php 160 foreach ($postboxes_with_coords as $index => $meta) { 161 $postboxId = $meta['postboxId']; 162 $deliveryServiceId = $meta['deliveryServiceId']; 163 $postcode = $meta['postcode']; 164 $name = $meta['name']; 165 $latitude = $meta['latitude']; 166 $longitude = $meta['longitude']; 167 ?> 168 <li class="postis-googlemap-location" 169 data-postboxes="<?php echo esc_attr(json_encode($meta, JSON_FORCE_OBJECT)); ?>" 170 data-lat="<?php echo esc_attr($latitude); ?>" 171 data-long="<?php echo esc_attr($longitude); ?>" 172 data-postbox-id="<?php echo esc_attr($postboxId); ?>" 173 data-delivery-service-id="<?php echo esc_attr($deliveryServiceId); ?>"> 174 <span><?php echo esc_html($name); ?></span> 175 <span>(<?php echo esc_html($postcode); ?>)</span> 176 </li> 177 <?php 178 } 179 ?> 180 </ul> 214 <?php echo postis_get_googlemap_locations_html(); ?> 181 215 <button data-remodal-action="confirm" class="postis-postbox-js remodal-confirm"><?php echo __("Choose Postbox", "postis"); ?></button> 182 216 </div> … … 188 222 </div> 189 223 <?php 190 } 191 } 192 } 224 } 225 226 227 /** 228 * Refresh the Google Map postbox list on checkout updates 229 **/ 230 function postis_hooks_googlemap_fragments( $fragments ){ 231 232 $fragments['ul.postis-googlemap-locations'] = postis_get_googlemap_locations_html(); 233 234 return $fragments; 235 } 236 237 238 /** 239 * Keep the customer's chosen Pósturinn service when the rates change 240 **/ 241 function postis_hooks_keep_chosen_shipping_service( $default, $rates, $chosen_method ){ 242 243 $pattern = '/^(postis:)?([A-Z]{3})[0-9]*$/'; 244 245 // Only act on our own rates (others look like local_pickup:1, flat_rate:3, free_shipping). 246 if ( ! is_string( $chosen_method ) || ! preg_match( $pattern, $chosen_method, $chosen_match ) ) { 247 return $default; 248 } 249 250 if ( ! is_array( $rates ) ) { 251 return $default; 252 } 253 254 // WooCommerce resets to the first rate whenever the rate list changes, and our 255 // rate IDs vary per postcode, so match on the service instead of the exact ID. 256 if ( isset( $rates[ $chosen_method ] ) ) { 257 return $chosen_method; 258 } 259 260 // DPH and DPL are both home delivery. 261 $same_service = array( 'DPL' => 'DPH' ); 262 $chosen_code = isset( $same_service[ $chosen_match[2] ] ) ? $same_service[ $chosen_match[2] ] : $chosen_match[2]; 263 264 foreach ( $rates as $rate_id => $rate ) { 265 if ( ! is_object( $rate ) || $rate->get_method_id() !== 'postis' || ! preg_match( $pattern, $rate_id, $rate_match ) ) { 266 continue; 267 } 268 269 $rate_code = isset( $same_service[ $rate_match[2] ] ) ? $same_service[ $rate_match[2] ] : $rate_match[2]; 270 271 if ( $rate_code === $chosen_code ) { 272 return $rate_id; 273 } 274 } 275 276 return $default; 277 } -
posturinn/tags/1.5.2/js/postis-googlemap.js
r3302192 r3807488 2 2 jQuery(function($) { 3 3 /** 4 * Load Google Map Modal4 * Get Google Map Modal (null when the dialog isn't in the DOM) 5 5 */ 6 var inst = $('[data-remodal-id=postis_googlemap_modal]').remodal(); 6 function getPostboxModal() { 7 var $el = $('[data-remodal-id=postis_googlemap_modal]'); 8 return $el.length ? $el.remodal() : null; 9 } 7 10 8 11 /** … … 10 13 */ 11 14 $(document.body).on('updated_checkout', function() { 15 // The postbox list was just replaced by the checkout fragment, so refresh the markers. 16 if (typeof map !== 'undefined' && map) { 17 addInitialPostboxMarkers(); 18 map.setCenter({ lat: 64.9995555, lng: -18.9839165 }); 19 map.setZoom(6); 20 } else if (typeof google !== 'undefined' && google.maps && document.getElementById('postis-map')) { 21 initMap(); 22 } 23 12 24 const shipping_wrapper = $('.woocommerce-shipping-methods'); 13 25 const get_shipping_method = shipping_wrapper.find('.shipping_method:checked').val(); … … 25 37 ) { 26 38 $('#postis_dpo_postbox_field').hide(); 27 inst.open(); 39 var inst = getPostboxModal(); 40 if (inst) { 41 inst.open(); 42 } 28 43 } 29 44 }); … … 74 89 $(document).on('click', '.postis-googlemap-modal-btn', function(e) { 75 90 e.preventDefault(); 76 inst.open(); 91 var inst = getPostboxModal(); 92 if (inst) { 93 inst.open(); 94 } 77 95 }); 78 96 }); … … 86 104 87 105 function initMap() { 106 if (typeof google === 'undefined' || !document.getElementById("postis-map")) { 107 return; 108 } 109 88 110 const Iceland = { lat: 64.9995555, lng: -18.9839165 }; 89 111 map = new google.maps.Map(document.getElementById("postis-map"), { … … 168 190 169 191 // Load map once window is ready 170 google.maps.event.addDomListener(window, 'load', initMap); 192 if (typeof google !== 'undefined' && google.maps) { 193 google.maps.event.addDomListener(window, 'load', initMap); 194 } -
posturinn/tags/1.5.2/readme.txt
r3570342 r3807488 3 3 Tags: shipping, posturinn, icelandic post shipping, shipping rates, woocommerce 4 4 Requires at least: 4.3 5 Tested up to: 7. 05 Tested up to: 7.1 6 6 Requires PHP: 7.4 7 Stable tag: 1.5. 17 Stable tag: 1.5.2 8 8 License: GPL2 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 17 17 18 18 This plugin is only for companies that have a registered user in Mappan. 19 20 Tested up to PHP 8.2. 19 21 20 22 == Installation == … … 26 28 27 29 == Changelog == 30 = 1.5.2 = 31 Fixed the "Choose Postbox" map popup not opening on the first checkout visit, and its postbox list now follows postcode changes 32 The chosen Pósturinn shipping method is kept when the postcode changes instead of jumping to another method 33 Fixed bulk "Pósturinn - Print Shipment PDF" and other bulk action notices not showing on the HPOS orders screen 34 28 35 = 1.5.1 = 29 36 minor changes -
posturinn/tags/1.5.2/wc-posturinn-shipping-api.php
r3570342 r3807488 3 3 * Plugin Name: Pósturinn's Shipping with WooCommerce 4 4 * Description: This plugin is an WooCommerce extension to extend shipping method with Pósturinn's - Iceland 5 * Version: 1.5. 15 * Version: 1.5.2 6 6 * Author: Pósturinn 7 7 * Author URI: https://postur.is … … 87 87 if ($gm_enable == 'yes') { 88 88 add_action( 'woocommerce_after_checkout_form', 'postis_hooks_after_checkout_form', 20 ); 89 } 89 add_filter( 'woocommerce_update_order_review_fragments', 'postis_hooks_googlemap_fragments' ); 90 } 91 92 add_filter( 'woocommerce_shipping_chosen_method', 'postis_hooks_keep_chosen_shipping_service', 10, 3 ); 90 93 91 94 $plugin_name = plugin_basename( __FILE__ ); -
posturinn/trunk/inc/hooks.php
r3570342 r3807488 72 72 wp_enqueue_script('postis-remodal', POSTIS_URL."/js/remodal.js", array('jquery'), '1.1.3', true); 73 73 74 wp_enqueue_script('postis-gm-js', POSTIS_URL."/js/postis-googlemap.js", array('jquery'), '1.1.3', true); 75 } 76 } 77 } 78 79 80 /** 81 * Render Extra Content After Checkout Form (Google Map) 82 **/ 83 function postis_hooks_after_checkout_form(){ 84 74 wp_enqueue_script('postis-gm-js', POSTIS_URL."/js/postis-googlemap.js", array('jquery'), postis_get_plugin_version(), true); 75 } 76 } 77 } 78 79 80 /** 81 * Build the Google Map postbox list (also refreshed through checkout fragments) 82 **/ 83 function postis_get_googlemap_locations_html(){ 84 85 $empty_list = '<ul class="postis-googlemap-locations"></ul>'; 86 87 if ( ! WC()->session ) { 88 return $empty_list; 89 } 90 85 91 // Get the exact same postbox services that the dropdown uses 86 92 $postbox_services = WC()->session->get('postis_postbox_services', array()); 87 88 if (!empty($postbox_services)) { 89 90 // We have the same data as the dropdown, now we need to get coordinates 91 // We'll need to call the postboxes API to get lat/lng for each service 92 $postboxes_with_coords = array(); 93 94 // Get postboxes API data for coordinates 93 94 if (empty($postbox_services)) { 95 return $empty_list; 96 } 97 98 // Only DPO/DNO services are postboxes 99 $postbox_service_list = array(); 100 foreach ($postbox_services as $service) { 101 $base_service_id = substr($service['deliveryServiceId'], 0, 3); 102 if ($base_service_id === 'DPO' || $base_service_id === 'DNO') { 103 $postbox_service_list[] = $service; 104 } 105 } 106 107 if (empty($postbox_service_list)) { 108 return $empty_list; 109 } 110 111 // Coordinates come from the postboxes API; cached because this runs on every checkout refresh 112 $postboxes_api_data = get_transient('postis_postboxes_coords'); 113 114 if (empty($postboxes_api_data) || !is_array($postboxes_api_data)) { 115 $postboxes_api_data = array(); 116 95 117 $endpoint_url = postis_get_endpoints('postboxes'); 96 118 $postis_apikey = postis_get_api_key(); 97 119 $domain = postis_get_homeurl(); 98 120 99 121 $req_headers = array( 100 122 "headers" => array( 101 'x-api-key' => $postis_apikey, 123 'x-api-key' => $postis_apikey, 102 124 'domain_name' => $domain, 103 125 'user-agent' => 'WooCommerce/'.postis_get_woocommerce_version().' | Postis/'.postis_get_plugin_version(), … … 106 128 ) 107 129 ); 108 130 109 131 $response = wp_remote_get($endpoint_url, $req_headers); 110 $postboxes_api_data = array(); 111 112 if (!is_wp_error($response) && $response['response']['code'] == 200) { 132 133 if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) == 200) { 113 134 $postboxes_response = json_decode(wp_remote_retrieve_body($response), true); 114 115 if ( isset($postboxes_response['postboxes'])) {135 136 if (!empty($postboxes_response['postboxes'])) { 116 137 // Index by postbox ID for quick lookup 117 138 foreach ($postboxes_response['postboxes'] as $postbox) { 118 139 $postboxes_api_data[$postbox['postboxId']] = $postbox; 119 140 } 141 142 set_transient('postis_postboxes_coords', $postboxes_api_data, HOUR_IN_SECONDS); 120 143 } 121 144 } 122 123 // Now combine the session services with coordinates from API 124 foreach ($postbox_services as $service) { 125 $service_id = $service['deliveryServiceId']; 126 $base_service_id = substr($service_id, 0, 3); 127 128 if ($base_service_id === 'DPO' || $base_service_id === 'DNO') { 129 // Extract postbox ID (remove DPO/DNO prefix) 130 $postbox_id = substr($service_id, 3); 131 132 // Get coordinates from API data 133 $coords = isset($postboxes_api_data[$postbox_id]) ? $postboxes_api_data[$postbox_id] : array(); 134 135 $postboxes_with_coords[] = array( 136 'deliveryServiceId' => $service_id, // Full ID like DPO9556 137 'postboxId' => $postbox_id, 138 'name' => $service['nameLong'], 139 'postcode' => isset($coords['postcode']) ? $coords['postcode'] : '', 140 'address' => isset($coords['address']) ? $coords['address'] : '', 141 'town' => isset($coords['town']) ? $coords['town'] : '', 142 'latitude' => isset($coords['latitude']) ? $coords['latitude'] : '', 143 'longitude' => isset($coords['longitude']) ? $coords['longitude'] : '', 144 ); 145 } 146 } 147 148 if (!empty($postboxes_with_coords)) { 145 } 146 147 // Combine the session services with coordinates from API 148 $postboxes_with_coords = array(); 149 foreach ($postbox_service_list as $service) { 150 $service_id = $service['deliveryServiceId']; 151 // Extract postbox ID (remove DPO/DNO prefix) 152 $postbox_id = substr($service_id, 3); 153 154 $coords = isset($postboxes_api_data[$postbox_id]) ? $postboxes_api_data[$postbox_id] : array(); 155 156 $postboxes_with_coords[] = array( 157 'deliveryServiceId' => $service_id, // Full ID like DPO9556 158 'postboxId' => $postbox_id, 159 'name' => $service['nameLong'], 160 'postcode' => isset($coords['postcode']) ? $coords['postcode'] : '', 161 'address' => isset($coords['address']) ? $coords['address'] : '', 162 'town' => isset($coords['town']) ? $coords['town'] : '', 163 'latitude' => isset($coords['latitude']) ? $coords['latitude'] : '', 164 'longitude' => isset($coords['longitude']) ? $coords['longitude'] : '', 165 ); 166 } 167 168 ob_start(); 169 ?> 170 <ul class="postis-googlemap-locations"> 171 <?php 172 foreach ($postboxes_with_coords as $index => $meta) { 173 $postboxId = $meta['postboxId']; 174 $deliveryServiceId = $meta['deliveryServiceId']; 175 $postcode = $meta['postcode']; 176 $name = $meta['name']; 177 $latitude = $meta['latitude']; 178 $longitude = $meta['longitude']; 179 ?> 180 <li class="postis-googlemap-location" 181 data-postboxes="<?php echo esc_attr(json_encode($meta, JSON_FORCE_OBJECT)); ?>" 182 data-lat="<?php echo esc_attr($latitude); ?>" 183 data-long="<?php echo esc_attr($longitude); ?>" 184 data-postbox-id="<?php echo esc_attr($postboxId); ?>" 185 data-delivery-service-id="<?php echo esc_attr($deliveryServiceId); ?>"> 186 <span><?php echo esc_html($name); ?></span> 187 <span>(<?php echo esc_html($postcode); ?>)</span> 188 </li> 189 <?php 190 } 191 ?> 192 </ul> 193 <?php 194 return ob_get_clean(); 195 } 196 197 198 /** 199 * Render Extra Content After Checkout Form (Google Map) 200 **/ 201 function postis_hooks_after_checkout_form(){ 202 203 // Always render the dialog: it sits outside the parts WooCommerce refreshes, 204 // so the list inside is kept current through the checkout fragments instead. 149 205 ?> 150 206 <div data-remodal-id="postis_googlemap_modal" role="dialog"> … … 155 211 <div class="postis-col-wrapper"> 156 212 <div class="postis-postboxes-section"> 157 <ul> 158 <?php 159 foreach ($postboxes_with_coords as $index => $meta) { 160 $postboxId = $meta['postboxId']; 161 $deliveryServiceId = $meta['deliveryServiceId']; 162 $postcode = $meta['postcode']; 163 $name = $meta['name']; 164 $latitude = $meta['latitude']; 165 $longitude = $meta['longitude']; 166 ?> 167 <li class="postis-googlemap-location" 168 data-postboxes="<?php echo esc_attr(json_encode($meta, JSON_FORCE_OBJECT)); ?>" 169 data-lat="<?php echo esc_attr($latitude); ?>" 170 data-long="<?php echo esc_attr($longitude); ?>" 171 data-postbox-id="<?php echo esc_attr($postboxId); ?>" 172 data-delivery-service-id="<?php echo esc_attr($deliveryServiceId); ?>"> 173 <span><?php echo esc_html($name); ?></span> 174 <span>(<?php echo esc_html($postcode); ?>)</span> 175 </li> 176 <?php 177 } 178 ?> 179 </ul> 213 <?php echo postis_get_googlemap_locations_html(); ?> 180 214 <button data-remodal-action="confirm" class="postis-postbox-js remodal-confirm"><?php echo __("Choose Postbox", "postis"); ?></button> 181 215 </div> … … 187 221 </div> 188 222 <?php 189 } 190 } 191 } 223 } 224 225 226 /** 227 * Refresh the Google Map postbox list on checkout updates 228 **/ 229 function postis_hooks_googlemap_fragments( $fragments ){ 230 231 $fragments['ul.postis-googlemap-locations'] = postis_get_googlemap_locations_html(); 232 233 return $fragments; 234 } 235 236 237 /** 238 * Keep the customer's chosen Pósturinn service when the rates change 239 **/ 240 function postis_hooks_keep_chosen_shipping_service( $default, $rates, $chosen_method ){ 241 242 $pattern = '/^(postis:)?([A-Z]{3})[0-9]*$/'; 243 244 // Only act on our own rates (others look like local_pickup:1, flat_rate:3, free_shipping). 245 if ( ! is_string( $chosen_method ) || ! preg_match( $pattern, $chosen_method, $chosen_match ) ) { 246 return $default; 247 } 248 249 if ( ! is_array( $rates ) ) { 250 return $default; 251 } 252 253 // WooCommerce resets to the first rate whenever the rate list changes, and our 254 // rate IDs vary per postcode, so match on the service instead of the exact ID. 255 if ( isset( $rates[ $chosen_method ] ) ) { 256 return $chosen_method; 257 } 258 259 // DPH and DPL are both home delivery. 260 $same_service = array( 'DPL' => 'DPH' ); 261 $chosen_code = isset( $same_service[ $chosen_match[2] ] ) ? $same_service[ $chosen_match[2] ] : $chosen_match[2]; 262 263 foreach ( $rates as $rate_id => $rate ) { 264 if ( ! is_object( $rate ) || $rate->get_method_id() !== 'postis' || ! preg_match( $pattern, $rate_id, $rate_match ) ) { 265 continue; 266 } 267 268 $rate_code = isset( $same_service[ $rate_match[2] ] ) ? $same_service[ $rate_match[2] ] : $rate_match[2]; 269 270 if ( $rate_code === $chosen_code ) { 271 return $rate_id; 272 } 273 } 274 275 return $default; 276 } -
posturinn/trunk/inc_hpos/admin.class.php
r3390272 r3807488 736 736 737 737 function bulk_admin_notices() { 738 global $post_type, $pagenow; 739 740 if ('edit.php' !== $pagenow || 'shop_order' !== $post_type || !isset($_REQUEST['bulk_action'])) { 738 $screen = function_exists('get_current_screen') ? get_current_screen() : null; 739 740 // With HPOS the orders list is admin.php?page=wc-orders, not edit.php?post_type=shop_order. 741 if (!$screen || wc_get_page_screen_id('shop-order') !== $screen->id || !isset($_REQUEST['bulk_action'])) { 741 742 return; 742 743 } -
posturinn/trunk/inc_hpos/hooks.php
r3570342 r3807488 73 73 wp_enqueue_script('postis-remodal', POSTIS_URL."/js/remodal.js", array('jquery'), '1.1.3', true); 74 74 75 wp_enqueue_script('postis-gm-js', POSTIS_URL."/js/postis-googlemap.js", array('jquery'), '1.1.3', true); 76 } 77 } 78 } 79 80 81 /** 82 * Render Extra Content After Checkout Form (Google Map) 83 **/ 84 function postis_hooks_after_checkout_form(){ 85 75 wp_enqueue_script('postis-gm-js', POSTIS_URL."/js/postis-googlemap.js", array('jquery'), postis_get_plugin_version(), true); 76 } 77 } 78 } 79 80 81 /** 82 * Build the Google Map postbox list (also refreshed through checkout fragments) 83 **/ 84 function postis_get_googlemap_locations_html(){ 85 86 $empty_list = '<ul class="postis-googlemap-locations"></ul>'; 87 88 if ( ! WC()->session ) { 89 return $empty_list; 90 } 91 86 92 // Get the exact same postbox services that the dropdown uses 87 93 $postbox_services = WC()->session->get('postis_postbox_services', array()); 88 89 if (!empty($postbox_services)) { 90 91 // We have the same data as the dropdown, now we need to get coordinates 92 // We'll need to call the postboxes API to get lat/lng for each service 93 $postboxes_with_coords = array(); 94 95 // Get postboxes API data for coordinates 94 95 if (empty($postbox_services)) { 96 return $empty_list; 97 } 98 99 // Only DPO/DNO services are postboxes 100 $postbox_service_list = array(); 101 foreach ($postbox_services as $service) { 102 $base_service_id = substr($service['deliveryServiceId'], 0, 3); 103 if ($base_service_id === 'DPO' || $base_service_id === 'DNO') { 104 $postbox_service_list[] = $service; 105 } 106 } 107 108 if (empty($postbox_service_list)) { 109 return $empty_list; 110 } 111 112 // Coordinates come from the postboxes API; cached because this runs on every checkout refresh 113 $postboxes_api_data = get_transient('postis_postboxes_coords'); 114 115 if (empty($postboxes_api_data) || !is_array($postboxes_api_data)) { 116 $postboxes_api_data = array(); 117 96 118 $endpoint_url = postis_get_endpoints('postboxes'); 97 119 $postis_apikey = postis_get_api_key(); 98 120 $domain = postis_get_homeurl(); 99 121 100 122 $req_headers = array( 101 123 "headers" => array( 102 'x-api-key' => $postis_apikey, 124 'x-api-key' => $postis_apikey, 103 125 'domain_name' => $domain, 104 126 'user-agent' => 'WooCommerce/'.postis_get_woocommerce_version().' | Postis/'.postis_get_plugin_version(), … … 107 129 ) 108 130 ); 109 131 110 132 $response = wp_remote_get($endpoint_url, $req_headers); 111 $postboxes_api_data = array(); 112 113 if (!is_wp_error($response) && $response['response']['code'] == 200) { 133 134 if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) == 200) { 114 135 $postboxes_response = json_decode(wp_remote_retrieve_body($response), true); 115 116 if ( isset($postboxes_response['postboxes'])) {136 137 if (!empty($postboxes_response['postboxes'])) { 117 138 // Index by postbox ID for quick lookup 118 139 foreach ($postboxes_response['postboxes'] as $postbox) { 119 140 $postboxes_api_data[$postbox['postboxId']] = $postbox; 120 141 } 142 143 set_transient('postis_postboxes_coords', $postboxes_api_data, HOUR_IN_SECONDS); 121 144 } 122 145 } 123 124 // Now combine the session services with coordinates from API 125 foreach ($postbox_services as $service) { 126 $service_id = $service['deliveryServiceId']; 127 $base_service_id = substr($service_id, 0, 3); 128 129 if ($base_service_id === 'DPO' || $base_service_id === 'DNO') { 130 // Extract postbox ID (remove DPO/DNO prefix) 131 $postbox_id = substr($service_id, 3); 132 133 // Get coordinates from API data 134 $coords = isset($postboxes_api_data[$postbox_id]) ? $postboxes_api_data[$postbox_id] : array(); 135 136 $postboxes_with_coords[] = array( 137 'deliveryServiceId' => $service_id, // Full ID like DPO9556 138 'postboxId' => $postbox_id, 139 'name' => $service['nameLong'], 140 'postcode' => isset($coords['postcode']) ? $coords['postcode'] : '', 141 'address' => isset($coords['address']) ? $coords['address'] : '', 142 'town' => isset($coords['town']) ? $coords['town'] : '', 143 'latitude' => isset($coords['latitude']) ? $coords['latitude'] : '', 144 'longitude' => isset($coords['longitude']) ? $coords['longitude'] : '', 145 ); 146 } 147 } 148 149 if (!empty($postboxes_with_coords)) { 146 } 147 148 // Combine the session services with coordinates from API 149 $postboxes_with_coords = array(); 150 foreach ($postbox_service_list as $service) { 151 $service_id = $service['deliveryServiceId']; 152 // Extract postbox ID (remove DPO/DNO prefix) 153 $postbox_id = substr($service_id, 3); 154 155 $coords = isset($postboxes_api_data[$postbox_id]) ? $postboxes_api_data[$postbox_id] : array(); 156 157 $postboxes_with_coords[] = array( 158 'deliveryServiceId' => $service_id, // Full ID like DPO9556 159 'postboxId' => $postbox_id, 160 'name' => $service['nameLong'], 161 'postcode' => isset($coords['postcode']) ? $coords['postcode'] : '', 162 'address' => isset($coords['address']) ? $coords['address'] : '', 163 'town' => isset($coords['town']) ? $coords['town'] : '', 164 'latitude' => isset($coords['latitude']) ? $coords['latitude'] : '', 165 'longitude' => isset($coords['longitude']) ? $coords['longitude'] : '', 166 ); 167 } 168 169 ob_start(); 170 ?> 171 <ul class="postis-googlemap-locations"> 172 <?php 173 foreach ($postboxes_with_coords as $index => $meta) { 174 $postboxId = $meta['postboxId']; 175 $deliveryServiceId = $meta['deliveryServiceId']; 176 $postcode = $meta['postcode']; 177 $name = $meta['name']; 178 $latitude = $meta['latitude']; 179 $longitude = $meta['longitude']; 180 ?> 181 <li class="postis-googlemap-location" 182 data-postboxes="<?php echo esc_attr(json_encode($meta, JSON_FORCE_OBJECT)); ?>" 183 data-lat="<?php echo esc_attr($latitude); ?>" 184 data-long="<?php echo esc_attr($longitude); ?>" 185 data-postbox-id="<?php echo esc_attr($postboxId); ?>" 186 data-delivery-service-id="<?php echo esc_attr($deliveryServiceId); ?>"> 187 <span><?php echo esc_html($name); ?></span> 188 <span>(<?php echo esc_html($postcode); ?>)</span> 189 </li> 190 <?php 191 } 192 ?> 193 </ul> 194 <?php 195 return ob_get_clean(); 196 } 197 198 199 /** 200 * Render Extra Content After Checkout Form (Google Map) 201 **/ 202 function postis_hooks_after_checkout_form(){ 203 204 // Always render the dialog: it sits outside the parts WooCommerce refreshes, 205 // so the list inside is kept current through the checkout fragments instead. 150 206 ?> 151 207 <div data-remodal-id="postis_googlemap_modal" role="dialog"> … … 156 212 <div class="postis-col-wrapper"> 157 213 <div class="postis-postboxes-section"> 158 <ul> 159 <?php 160 foreach ($postboxes_with_coords as $index => $meta) { 161 $postboxId = $meta['postboxId']; 162 $deliveryServiceId = $meta['deliveryServiceId']; 163 $postcode = $meta['postcode']; 164 $name = $meta['name']; 165 $latitude = $meta['latitude']; 166 $longitude = $meta['longitude']; 167 ?> 168 <li class="postis-googlemap-location" 169 data-postboxes="<?php echo esc_attr(json_encode($meta, JSON_FORCE_OBJECT)); ?>" 170 data-lat="<?php echo esc_attr($latitude); ?>" 171 data-long="<?php echo esc_attr($longitude); ?>" 172 data-postbox-id="<?php echo esc_attr($postboxId); ?>" 173 data-delivery-service-id="<?php echo esc_attr($deliveryServiceId); ?>"> 174 <span><?php echo esc_html($name); ?></span> 175 <span>(<?php echo esc_html($postcode); ?>)</span> 176 </li> 177 <?php 178 } 179 ?> 180 </ul> 214 <?php echo postis_get_googlemap_locations_html(); ?> 181 215 <button data-remodal-action="confirm" class="postis-postbox-js remodal-confirm"><?php echo __("Choose Postbox", "postis"); ?></button> 182 216 </div> … … 188 222 </div> 189 223 <?php 190 } 191 } 192 } 224 } 225 226 227 /** 228 * Refresh the Google Map postbox list on checkout updates 229 **/ 230 function postis_hooks_googlemap_fragments( $fragments ){ 231 232 $fragments['ul.postis-googlemap-locations'] = postis_get_googlemap_locations_html(); 233 234 return $fragments; 235 } 236 237 238 /** 239 * Keep the customer's chosen Pósturinn service when the rates change 240 **/ 241 function postis_hooks_keep_chosen_shipping_service( $default, $rates, $chosen_method ){ 242 243 $pattern = '/^(postis:)?([A-Z]{3})[0-9]*$/'; 244 245 // Only act on our own rates (others look like local_pickup:1, flat_rate:3, free_shipping). 246 if ( ! is_string( $chosen_method ) || ! preg_match( $pattern, $chosen_method, $chosen_match ) ) { 247 return $default; 248 } 249 250 if ( ! is_array( $rates ) ) { 251 return $default; 252 } 253 254 // WooCommerce resets to the first rate whenever the rate list changes, and our 255 // rate IDs vary per postcode, so match on the service instead of the exact ID. 256 if ( isset( $rates[ $chosen_method ] ) ) { 257 return $chosen_method; 258 } 259 260 // DPH and DPL are both home delivery. 261 $same_service = array( 'DPL' => 'DPH' ); 262 $chosen_code = isset( $same_service[ $chosen_match[2] ] ) ? $same_service[ $chosen_match[2] ] : $chosen_match[2]; 263 264 foreach ( $rates as $rate_id => $rate ) { 265 if ( ! is_object( $rate ) || $rate->get_method_id() !== 'postis' || ! preg_match( $pattern, $rate_id, $rate_match ) ) { 266 continue; 267 } 268 269 $rate_code = isset( $same_service[ $rate_match[2] ] ) ? $same_service[ $rate_match[2] ] : $rate_match[2]; 270 271 if ( $rate_code === $chosen_code ) { 272 return $rate_id; 273 } 274 } 275 276 return $default; 277 } -
posturinn/trunk/js/postis-googlemap.js
r3302192 r3807488 2 2 jQuery(function($) { 3 3 /** 4 * Load Google Map Modal4 * Get Google Map Modal (null when the dialog isn't in the DOM) 5 5 */ 6 var inst = $('[data-remodal-id=postis_googlemap_modal]').remodal(); 6 function getPostboxModal() { 7 var $el = $('[data-remodal-id=postis_googlemap_modal]'); 8 return $el.length ? $el.remodal() : null; 9 } 7 10 8 11 /** … … 10 13 */ 11 14 $(document.body).on('updated_checkout', function() { 15 // The postbox list was just replaced by the checkout fragment, so refresh the markers. 16 if (typeof map !== 'undefined' && map) { 17 addInitialPostboxMarkers(); 18 map.setCenter({ lat: 64.9995555, lng: -18.9839165 }); 19 map.setZoom(6); 20 } else if (typeof google !== 'undefined' && google.maps && document.getElementById('postis-map')) { 21 initMap(); 22 } 23 12 24 const shipping_wrapper = $('.woocommerce-shipping-methods'); 13 25 const get_shipping_method = shipping_wrapper.find('.shipping_method:checked').val(); … … 25 37 ) { 26 38 $('#postis_dpo_postbox_field').hide(); 27 inst.open(); 39 var inst = getPostboxModal(); 40 if (inst) { 41 inst.open(); 42 } 28 43 } 29 44 }); … … 74 89 $(document).on('click', '.postis-googlemap-modal-btn', function(e) { 75 90 e.preventDefault(); 76 inst.open(); 91 var inst = getPostboxModal(); 92 if (inst) { 93 inst.open(); 94 } 77 95 }); 78 96 }); … … 86 104 87 105 function initMap() { 106 if (typeof google === 'undefined' || !document.getElementById("postis-map")) { 107 return; 108 } 109 88 110 const Iceland = { lat: 64.9995555, lng: -18.9839165 }; 89 111 map = new google.maps.Map(document.getElementById("postis-map"), { … … 168 190 169 191 // Load map once window is ready 170 google.maps.event.addDomListener(window, 'load', initMap); 192 if (typeof google !== 'undefined' && google.maps) { 193 google.maps.event.addDomListener(window, 'load', initMap); 194 } -
posturinn/trunk/readme.txt
r3570342 r3807488 3 3 Tags: shipping, posturinn, icelandic post shipping, shipping rates, woocommerce 4 4 Requires at least: 4.3 5 Tested up to: 7. 05 Tested up to: 7.1 6 6 Requires PHP: 7.4 7 Stable tag: 1.5. 17 Stable tag: 1.5.2 8 8 License: GPL2 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 17 17 18 18 This plugin is only for companies that have a registered user in Mappan. 19 20 Tested up to PHP 8.2. 19 21 20 22 == Installation == … … 26 28 27 29 == Changelog == 30 = 1.5.2 = 31 Fixed the "Choose Postbox" map popup not opening on the first checkout visit, and its postbox list now follows postcode changes 32 The chosen Pósturinn shipping method is kept when the postcode changes instead of jumping to another method 33 Fixed bulk "Pósturinn - Print Shipment PDF" and other bulk action notices not showing on the HPOS orders screen 34 28 35 = 1.5.1 = 29 36 minor changes -
posturinn/trunk/wc-posturinn-shipping-api.php
r3570342 r3807488 3 3 * Plugin Name: Pósturinn's Shipping with WooCommerce 4 4 * Description: This plugin is an WooCommerce extension to extend shipping method with Pósturinn's - Iceland 5 * Version: 1.5. 15 * Version: 1.5.2 6 6 * Author: Pósturinn 7 7 * Author URI: https://postur.is … … 87 87 if ($gm_enable == 'yes') { 88 88 add_action( 'woocommerce_after_checkout_form', 'postis_hooks_after_checkout_form', 20 ); 89 } 89 add_filter( 'woocommerce_update_order_review_fragments', 'postis_hooks_googlemap_fragments' ); 90 } 91 92 add_filter( 'woocommerce_shipping_chosen_method', 'postis_hooks_keep_chosen_shipping_service', 10, 3 ); 90 93 91 94 $plugin_name = plugin_basename( __FILE__ );
Note:
See TracChangeset
for help on using the changeset viewer.