Changeset 3254068
- Timestamp:
- 03/11/2025 01:03:20 PM (13 months ago)
- Location:
- cod24-shipping
- Files:
-
- 33 added
- 4 deleted
- 7 edited
-
tags/3.4.6/readme.txt (deleted)
-
tags/4.0 (added)
-
tags/4.0/assets (added)
-
tags/4.0/assets/css (added)
-
tags/4.0/assets/css/cod24-woo-admin.css (added)
-
tags/4.0/assets/css/sweetalert2.css (added)
-
tags/4.0/assets/index.php (added)
-
tags/4.0/assets/js (added)
-
tags/4.0/assets/js/city-select.js (added)
-
tags/4.0/assets/js/cod24-shcod-fee.js (added)
-
tags/4.0/assets/js/cod24-woo-admin.js (added)
-
tags/4.0/assets/js/sweetalert2.js (added)
-
tags/4.0/cod24-shipping.php (added)
-
tags/4.0/inc (added)
-
tags/4.0/inc/api (added)
-
tags/4.0/inc/api/class-cod24-api.php (added)
-
tags/4.0/inc/api/class-cod24-tipax-api.php (added)
-
tags/4.0/inc/class-cod24-settings.php (added)
-
tags/4.0/inc/class-cod24-shcod.php (added)
-
tags/4.0/inc/class-cod24-woo.php (added)
-
tags/4.0/inc/index.php (added)
-
tags/4.0/inc/shipping (added)
-
tags/4.0/inc/shipping/class-cod24-pishtaz.php (added)
-
tags/4.0/inc/shipping/class-cod24-special.php (added)
-
tags/4.0/inc/shipping/class-cod24-tipax.php (added)
-
tags/4.0/index.php (added)
-
tags/4.0/readme.txt (added)
-
trunk/assets/css/cod24-woo-admin.css (modified) (1 diff)
-
trunk/assets/js/city-select.js (modified) (3 diffs)
-
trunk/assets/js/cod24-woo-admin.js (modified) (10 diffs)
-
trunk/cod24-shipping.php (modified) (4 diffs)
-
trunk/inc/api (added)
-
trunk/inc/api/class-cod24-api.php (added)
-
trunk/inc/api/class-cod24-tipax-api.php (added)
-
trunk/inc/class-cod24-api.php (deleted)
-
trunk/inc/class-cod24-pishtaz.php (deleted)
-
trunk/inc/class-cod24-shcod.php (modified) (1 diff)
-
trunk/inc/class-cod24-special.php (deleted)
-
trunk/inc/class-cod24-woo.php (modified) (52 diffs)
-
trunk/inc/shipping (added)
-
trunk/inc/shipping/class-cod24-pishtaz.php (added)
-
trunk/inc/shipping/class-cod24-special.php (added)
-
trunk/inc/shipping/class-cod24-tipax.php (added)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cod24-shipping/trunk/assets/css/cod24-woo-admin.css
r3191219 r3254068 38 38 height: 30px; 39 39 } 40 .cod24-post-section, .cod24-tipax-section { 41 display: none; 42 } 43 .cod24-post-section.active, .cod24-tipax-section.active { 44 display: block; 45 } 46 .cod24-dimension-fields { 47 display: flex; 48 justify-content: space-between; 49 } 50 .cod24-dimension-fields > input { 51 width: 30%; 52 } 40 53 .cod24-meta-fields > .description { 41 54 color: #31708f; -
cod24-shipping/trunk/assets/js/city-select.js
r3191219 r3254068 96 96 97 97 /* City select boxes */ 98 var cities = wc_city_select_params.cities; 99 var states = wc_city_select_params.states; 98 var post_states = wc_city_select_params.post_states; 99 var post_cities = wc_city_select_params.post_cities; 100 var tipax_states = wc_city_select_params.tipax_states; 101 var tipax_cities = wc_city_select_params.tipax_cities; 100 102 101 // $( 'body' ).on( 'country_to_state_changing', function(e, country, $container) { 102 // var $statebox = $container.find( '#billing_state, #shipping_state, #calc_shipping_state' ); 103 // var state = $statebox.val(); 104 // $( document.body ).trigger( 'state_changing', [country, state, $container ] ); 105 // }); 106 107 $( 'body' ).on( 'change', 'select.state_select, #calc_shipping_state, input[name=payment_method][value=cod]', function() { 108 var $container = $( this ).closest( 'div' ); 103 $( 'body' ).on( 'change', 'select.state_select, #calc_shipping_state, input[name=payment_method][value=cod], .shipping_method', function() { 104 var $container = $( this ).closest( 'form' ); 109 105 var country = $container.find( '#billing_country, #shipping_country, #calc_shipping_country' ).val(); 110 var state = $( this ).val(); 111 112 $( document.body ).trigger( 'state_changing', [country, state, $container ] ); 106 var shipToDifferentAddress = $('#ship-to-different-address-checkbox').is(':checked'); 107 var state = shipToDifferentAddress ? $('#shipping_state').val() : $('#billing_state').val(); 108 var shipping_method = ( $('.shipping_method:checked').val() ) ? $('.shipping_method:checked').val() : $('.shipping_method:first-child').val(); 109 $( document.body ).trigger( 'state_changing', [country, state, shipping_method, $container ] ); 113 110 }); 114 111 115 $( 'body' ).on( 'change', 'input[name=payment_method], #shipping_city, #billing_city', function() {112 $( 'body' ).on( 'change', 'input[name=payment_method], .shipping_method, #shipping_city, #billing_city', function() { 116 113 $( document.body ).trigger('update_checkout'); 117 114 }); 118 115 119 $( 'body' ).on( 'state_changing', function(e, country, state, $container) {116 $( 'body' ).on( 'state_changing', function(e, country, state, shipping_method, $container) { 120 117 var $citybox = $container.find( '#billing_city, #shipping_city, #calc_shipping_city' ); 118 119 if (shipping_method.includes('cod24_tipax')) 120 { 121 var type = 'tipax'; 122 var cities = tipax_cities; 123 var states = tipax_states; 124 } 125 else 126 { 127 var type = 'post'; 128 var cities = post_cities; 129 var states = post_states; 130 } 131 121 132 var user_state_id; 122 133 $.each(states, function(i, v) { 123 134 if (v.shortNameEn == state) { 124 user_state_id =v.statePostCode;125 return;135 user_state_id = (type == 'tipax') ? v.stateCode : v.statePostCode; 136 return; // Exit loop 126 137 } 127 138 }); 128 139 129 140 if ( user_state_id ) { 130 141 /* if the country has no states */ 131 142 var user_cities = []; 132 143 $.each(cities, function(i, v) { 133 if (v.statePostCode == user_state_id) { 134 var tmp_city = []; 135 tmp_city['id'] = v.cityPostCode; 136 tmp_city['name'] = v.cityNameFa; 137 user_cities.push(tmp_city); 138 return; 139 } 144 if( type == 'tipax') { 145 if (v.stateCode == user_state_id) { 146 var tmp_city = []; 147 tmp_city['id'] = v.cityCode; 148 tmp_city['name'] = v.cityNameFa; 149 user_cities.push(tmp_city); 150 return; 151 } 152 } 153 else { 154 if (v.statePostCode == user_state_id) { 155 var tmp_city = []; 156 tmp_city['id'] = v.cityPostCode; 157 tmp_city['name'] = v.cityNameFa; 158 user_cities.push(tmp_city); 159 return; 160 } 161 } 140 162 }); 163 141 164 142 165 if( user_cities ) { … … 177 200 function disableCity( $citybox ) 178 201 { 179 $citybox.val( '').change();202 $citybox.val('').change(); 180 203 $citybox.prop( 'disabled', true ); 181 204 } … … 198 221 var options = ''; 199 222 for (i = 0; i < current_cities.length; i++) { 200 var cityId = current_cities[ i].id;201 var cityName = current_cities[ i].name;223 var cityId = current_cities[i].id; 224 var cityName = current_cities[i].name; 202 225 options = options + '<option value="' + sanitizeFirstLastSpaceCharacter( cityName ) + '">' + sanitizeFirstLastSpaceCharacter( cityName ) + '</option>'; 203 226 } 204 227 205 $citybox.html( '<option value="">' + wc_city_select_params.i18n_select_city_text + '</option>' + options);228 $citybox.html('<option value="">' + wc_city_select_params.i18n_select_city_text + '</option>' + options); 206 229 207 230 if ( $('option[value="'+value+'"]', $citybox).length ) { -
cod24-shipping/trunk/assets/js/cod24-woo-admin.js
r3204044 r3254068 6 6 $.each(cod24_woo_params.options.carton_size.options, function(value, text) { // value is the key, text is the display name 7 7 // Concatenate each option string to the options variable 8 carton_options += '<option value="' + value + '">' + text + '</option>'; 8 var sizes = value.split("-"); 9 if( sizes.length == 3 ) 10 carton_options += '<option value="' + value + '" data-length="' + sizes[0] + '" data-width="' + sizes[1] + '" data-height="' + sizes[2] + '">' + text + '</option>'; 11 else 12 carton_options += '<option value="' + value + '">' + text + '</option>'; 9 13 }); 10 14 … … 46 50 </select> 47 51 </div> 52 <div class="cod24-fields"> 53 <div class="label" style="margin-bottom:10px"><label for="dimension_length">`+ cod24_woo_params.options.dimension.label +`</label></div> 54 <input type="text" class="dimension_length" style="width:19%" id="dimension_length" style="margin-bottom:0px" name="dimension_length" placeholder="` + cod24_woo_params.options.dimension.length_placeholder + `"/> 55 <input type="text" class="dimension_width" style="width:19%" id="dimension_width" style="margin-bottom:0px" name="dimension_width" placeholder="` + cod24_woo_params.options.dimension.width_placeholder + `"/> 56 <input type="text" class="dimension_height" style="width:19%" id="dimension_height" style="margin-bottom:0px" name="dimension_height" placeholder="` + cod24_woo_params.options.dimension.height_placeholder + `"/> 57 </div> 48 58 <div class="cod24-fields"><input type="hidden" id="cod24_form_nonce" name="cod24_form_nonce" value="` + cod24_woo_params.options.cod24_form_nonce + `" /></div> 49 59 </div> … … 54 64 const custom_total_weight = weight_type === 'custom_weight' ? document.getElementById('custom_total_weight').value : null; 55 65 const carton_size = document.getElementById('carton_size').value; 66 const dimension_length = document.getElementById('dimension_length').value; 67 const dimension_width = document.getElementById('dimension_width').value; 68 const dimension_height = document.getElementById('dimension_height').value; 56 69 const cod24_form_nonce = document.getElementById('cod24_form_nonce').value; 57 70 … … 63 76 } 64 77 65 return { weight_type, custom_total_weight, carton_size, cod24_form_nonce };78 return { weight_type, custom_total_weight, carton_size, cod24_form_nonce, dimension_length, dimension_width, dimension_height }; 66 79 }, 67 80 showCloseButton: true, … … 82 95 custom_total_weight: result.value.custom_total_weight, 83 96 carton_size: result.value.carton_size, 97 dimension_length: result.value.dimension_length, 98 dimension_width: result.value.dimension_width, 99 dimension_height: result.value.dimension_height, 84 100 order_ids: getSelectedOrderIDs() 85 101 }, … … 97 113 }, 98 114 success: function (response) { 99 console.log(response);100 115 if (response && response.status === true) { 101 116 Swal.fire( … … 188 203 }, 189 204 success: function (response) { 190 console.log(response);191 205 if( response && response.status === true ) 192 206 { … … 232 246 function getSelectedOrderIDs() { 233 247 var orderIDs = []; 234 $('input[name="id[]"]:checked , input[name="post[]"]:checked').each(function () {248 $('input[name="id[]"]:checked').each(function () { 235 249 orderIDs.push($(this).val()); 236 250 }); 237 238 239 251 return orderIDs; 240 252 } 253 254 jQuery("#cod24_shipping_type").on('change', function(e) { 255 if (jQuery(this).val() == 'tipax') { 256 jQuery('select[name=cod24_status] option[value=cod24-suspend]').prop('disabled', true); 257 jQuery('.cod24-tipax-section').slideDown(2000); 258 jQuery('.cod24-post-section').slideUp(2000); 259 } else { 260 jQuery('select[name=cod24_status] option[value=cod24-suspend]').prop('disabled', false); 261 jQuery('.cod24-post-section').slideDown(2000); 262 jQuery('.cod24-tipax-section').slideUp(2000); 263 } 264 }); 265 266 jQuery(".tipax_carton_size").on('change', function(e){ 267 var selected_carton_size = jQuery(this).val(); 268 var selectedOption = jQuery(this).find('option:selected'); 269 var selected_dimension_length = selectedOption.data('length'); 270 var selected_dimension_width = selectedOption.data('width'); 271 var selected_dimension_height = selectedOption.data('height'); 272 if( selected_carton_size == 'none' || selected_carton_size == 'other' ) 273 { 274 jQuery('.dimension-length').val(''); 275 jQuery('.dimension-width').val(''); 276 jQuery('.dimension-height').val(''); 277 } 278 else 279 { 280 jQuery('.dimension-length').val(selected_dimension_length); 281 jQuery('.dimension-width').val(selected_dimension_width); 282 jQuery('.dimension-height').val(selected_dimension_height); 283 } 284 }); 285 286 jQuery(document).on('change', "#carton_size", function(e){ 287 var selected_carton_size = jQuery(this).val(); 288 var selectedOption = jQuery(this).find('option:selected'); 289 var selected_dimension_length = selectedOption.data('length'); 290 var selected_dimension_width = selectedOption.data('width'); 291 var selected_dimension_height = selectedOption.data('height'); 292 if( selected_carton_size == 'none' || selected_carton_size == 'other' ) 293 { 294 jQuery('#dimension_length').val(''); 295 jQuery('#dimension_width').val(''); 296 jQuery('#dimension_height').val(''); 297 } 298 else 299 { 300 jQuery('#dimension_length').val(selected_dimension_length); 301 jQuery('#dimension_width').val(selected_dimension_width); 302 jQuery('#dimension_height').val(selected_dimension_height); 303 } 304 }); 241 305 242 306 jQuery(".cod24_change_status").on('click', function(e){ 243 307 e.preventDefault(); 244 var order_barcode_nonce = jQuery('.order_barcode_nonce').val(); 245 var order_id = jQuery('.order_id').val(); 246 var total_weight = jQuery('.custom_total_weight').val(); 247 var carton_size = jQuery('.carton_size').val(); 248 var content_parcel = jQuery('.content_parcel').val(); 308 309 var container = jQuery('#cod24_order_info'); 310 if (!container.length) { 311 console.error('Container with id="cod24_order_info" not found'); 312 return; 313 } 314 315 // Create FormData object 316 var data = new FormData(); 317 318 // Get all input, select, and textarea elements within the container 319 container.find('input, select, textarea').each(function() { 320 var element = jQuery(this); 321 var name = element.attr('name'); // Use the 'name' attribute as the key 322 323 // Skip elements without a 'name' attribute 324 if (!name) { 325 console.warn('Element without name attribute skipped:', element); 326 return; 327 } 328 329 // Handle checkboxes separately 330 if (element.attr('type') === 'checkbox') { 331 var value = element.is(':checked') ? 'yes' : 'no'; // Set value to 'yes' or 'no' 332 data.append(name, value); 333 } else { 334 // Handle other input types (text, select, textarea, etc.) 335 var value = element.val(); // Get the value of the element 336 data.append(name, value); 337 } 338 }); 339 340 // Append additional data (e.g., action) 341 data.append('action', 'cod24_change_status'); 249 342 // Set the value based on whether it is checked or not 250 var non_standard_package_isChecked = jQuery('.non_standard_package').is(':checked'); 251 if (non_standard_package_isChecked) { 252 var non_standard_package = 'yes'; 253 } else { 254 var non_standard_package = 'no'; 255 } 256 var cod24_status = jQuery('.cod24_status').val(); 343 // var non_standard_package_isChecked = jQuery('.non_standard_package').is(':checked'); 344 // if (non_standard_package_isChecked) { 345 // var non_standard_package = 'yes'; 346 // } else { 347 // var non_standard_package = 'no'; 348 // } 257 349 jQuery.ajax({ 258 350 type : "post", 259 351 dataType : "json", 260 352 url : cod24_woo_params.ajax_url, 261 data : { action: "cod24_change_status", order_id : order_id, order_barcode_nonce: order_barcode_nonce, total_weight : total_weight, non_standard_package : non_standard_package, carton_size: carton_size, content_parcel: content_parcel, cod24_status : cod24_status }, 353 data : data, 354 processData: false, 355 contentType: false, 262 356 beforeSend: function() { 263 357 Swal.fire({ … … 271 365 }, 272 366 success: function(response) { 273 console.log(response);274 367 if (response && response.status === true) { 275 368 Swal.fire( … … 314 407 }, 315 408 success: function(response) { 316 console.log(response);317 409 if( response && response.status === true ) 318 410 { -
cod24-shipping/trunk/cod24-shipping.php
r3248145 r3254068 3 3 Plugin Name: COD24 Shipping For Woocommerce 4 4 Description: This plugin is adding COD24 shipping methods to woocommerce. 5 Version: 3.4.65 Version: 4.0 6 6 Author: COD24 7 7 Author URI: https://cod24.ir … … 27 27 public function __construct() 28 28 { 29 define('COD24_PLUGIN_VERSION', ' 3.4.6');29 define('COD24_PLUGIN_VERSION', '4.0'); 30 30 define('COD24_PLUGIN_DIR', plugin_dir_path(__FILE__)); 31 31 define('COD24_PLUGIN_URL', plugin_dir_url(__FILE__)); 32 32 33 // load textdomain 34 add_action( 'plugins_loaded', array( __CLASS__ , 'cod24_load_plugin_textdomain' ) ); 35 36 // include 37 require_once('inc/class-cod24-api.php'); 38 require_once('inc/class-cod24-pishtaz.php'); 39 require_once('inc/class-cod24-special.php'); 33 // Include required files 34 require_once('inc/api/class-cod24-api.php'); 35 require_once('inc/api/class-cod24-tipax-api.php'); 36 require_once('inc/shipping/class-cod24-pishtaz.php'); 37 require_once('inc/shipping/class-cod24-special.php'); 38 require_once('inc/shipping/class-cod24-tipax.php'); 40 39 require_once('inc/class-cod24-shcod.php'); 41 40 require_once('inc/class-cod24-woo.php'); 42 41 require_once('inc/class-cod24-settings.php'); 43 44 } // END public function __construct()45 42 46 public static function cod24_load_plugin_textdomain() { 47 load_plugin_textdomain( 'cod24-shipping', false, basename( dirname( __FILE__ ) ) . '/languages/' ); 48 } 43 // Schedule the cron job to run once (e.g., 2 minutes from now) 44 if (!get_option('cod24_meta_data_migrated')) { 45 if (!wp_next_scheduled('migrate_cod24_meta_data_cron')) { 46 wp_schedule_single_event(time() + 120, 'migrate_cod24_meta_data_cron'); 47 } 48 add_action('migrate_cod24_meta_data_cron', array(__CLASS__, 'migrate_cod24_meta_data')); 49 } 50 } 51 52 /** 53 * Migrate old COD24 meta data to the new structure. 54 * 55 * @return void 56 */ 57 public static function migrate_cod24_meta_data() 58 { 59 // Get all orders 60 $args = array( 61 'limit' => -1, // Get all orders 62 'return' => 'ids', // Return only order IDs 63 ); 64 65 $orders = wc_get_orders($args); 66 67 foreach ($orders as $order_id) { 68 $order = wc_get_order($order_id); 69 70 // Check if the old meta keys exist 71 $order_cod24_serial = $order->get_meta('_cod24_serial', true); 72 $order_cod24_barcode = $order->get_meta('_cod24_barcode', true); 73 $order_cod24_serial_postmeta = get_post_meta($order->get_id(), '_cod24_serial', true); 74 $order_cod24_barcode_postmeta = get_post_meta($order->get_id(), '_cod24_barcode', true); 75 76 if (!empty($order_cod24_serial) || !empty($order_cod24_barcode)) { 77 // Get the existing _cod24_info meta or initialize a new array 78 $cod24_info = $order->get_meta('_cod24_info', true); 79 if (empty($cod24_info)) { 80 $cod24_info = array( 81 'total_weight' => '', 82 'shipping_type' => 'post', 83 'serial' => '', 84 'barcode' => '', 85 'data' => '' 86 ); 87 } 88 89 // Migrate the old meta data to the new structure 90 if (!empty($order_cod24_serial)) { 91 $cod24_info['serial'] = $order_cod24_serial; 92 $order->delete_meta_data('_cod24_serial'); // Remove old meta 93 } 94 95 if (!empty($order_cod24_barcode)) { 96 $cod24_info['barcode'] = $order_cod24_barcode; 97 $order->delete_meta_data('_cod24_barcode'); // Remove old meta 98 } 99 100 // Update the order with the new meta structure 101 $order->update_meta_data('_cod24_info', $cod24_info); 102 $order->save(); 103 } elseif (!empty($order_cod24_serial_postmeta) || !empty($order_cod24_barcode_postmeta)) { 104 // Get the existing _cod24_info meta or initialize a new array 105 $cod24_info = $order->get_meta('_cod24_info', true); 106 if (empty($cod24_info)) { 107 $cod24_info = array( 108 'total_weight' => '', 109 'shipping_type' => 'post', 110 'serial' => '', 111 'barcode' => '', 112 'data' => '' 113 ); 114 } 115 116 // Migrate the old meta data to the new structure 117 if (!empty($order_cod24_serial_postmeta)) { 118 $cod24_info['serial'] = $order_cod24_serial_postmeta; 119 $order->delete_meta_data('_cod24_serial'); // Remove old meta 120 delete_post_meta($order->get_id(), '_cod24_serial'); 121 } 122 123 if (!empty($order_cod24_barcode_postmeta)) { 124 $cod24_info['barcode'] = $order_cod24_barcode_postmeta; 125 $order->delete_meta_data('_cod24_barcode'); // Remove old meta 126 delete_post_meta($order->get_id(), '_cod24_barcode'); 127 } 128 129 // Update the order with the new meta structure 130 $order->update_meta_data('_cod24_info', $cod24_info); 131 $order->save(); 132 } 133 } 134 135 // Mark the migration as completed 136 update_option('cod24_meta_data_migrated', true); 137 } 49 138 50 139 /** … … 54 143 { 55 144 // Do nothing 56 } // END public static function activate145 } 57 146 58 147 /** … … 62 151 { 63 152 // Do nothing 64 } // END public static function deactivate 65 66 } // END class COD24_Shipping 67 } // END if(!class_exists('COD24_Shipping')) 153 } 154 } 155 } 68 156 69 157 if (class_exists('COD24_Shipping\\COD24_Shipping')) { -
cod24-shipping/trunk/inc/class-cod24-shcod.php
r3191219 r3254068 32 32 add_action( 'wp_ajax_nopriv_shipping_on_delivery' , array( &$this , 'get_ajax_shipping_on_delivery_fee' ) ); 33 33 add_action( 'woocommerce_cart_calculate_fees' , array( &$this , 'add_remove_shipping_on_delivery_fee' ) ); 34 add_action( 'woocommerce_checkout_update_order_meta' , array( &$this , 'save_shipping_on_delivery_field' ) );34 add_action( 'woocommerce_checkout_update_order_meta' , array( &$this , 'save_shipping_on_delivery_field' ), 990 ); 35 35 36 36 // woocommerce change available payment gateways -
cod24-shipping/trunk/inc/class-cod24-woo.php
r3246260 r3254068 6 6 * Package: COD24 Shipping 7 7 * Author: COD24 8 * Last Modified Time: 202 4/12/04 00:20:508 * Last Modified Time: 2025/03/11 13:32:06 9 9 * License: GPL-2.0+ 10 10 * License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 44 44 45 45 // set custom total weight in woocommerce thankyou 46 add_action( 'woocommerce_checkout_update_order_meta' , array( &$this , 'checkout_save_ total_weight_meta' ));46 add_action( 'woocommerce_checkout_update_order_meta' , array( &$this , 'checkout_save_cod24_meta' ), 991 ); 47 47 48 48 // order metabox & ajax handler 49 49 add_action( 'add_meta_boxes' , array( &$this , 'order_detail_metabox' ) ); 50 add_action( 'save_post_shop_order', array( &$this , 'save_order_custom_total_weight' ) ); 51 add_action( 'save_post_shop_order', array( &$this , 'save_order_non_standard_package' ) ); 52 add_action( 'save_post_shop_order', array( &$this , 'save_order_carton_size' ) ); 53 add_action( 'save_post_shop_order', array( &$this , 'save_order_content_parcel' ) ); 50 add_action( 'save_post_shop_order', array( &$this , 'save_order_cod24_fields' ) ); 51 add_action( 'woocommerce_process_shop_order_meta', array( $this, 'save_order_cod24_fields' ) ); 54 52 55 53 // ajax handler for receive cod24 serial … … 95 93 wp_enqueue_script( 'wc-city-select', $city_select_path, array( 'jquery' ), COD24_PLUGIN_VERSION, true ); 96 94 97 $states_data = COD24_API::get_states(); 98 $cities_data = COD24_API::get_all_cities(); 95 $post_states = COD24_API::get_states(); 96 $post_cities = COD24_API::get_all_cities(); 97 $tipax_states = COD24_Tipax_API::get_states(); 98 $tipax_cities = COD24_Tipax_API::get_all_cities(); 99 99 100 100 wp_localize_script( 'wc-city-select', 'wc_city_select_params', array( 101 'states' => $states_data, 102 'cities' => $cities_data, 101 'post_states' => $post_states, 102 'post_cities' => $post_cities, 103 'tipax_states' => $tipax_states, 104 'tipax_cities' => $tipax_cities, 103 105 'ajaxurl' => admin_url('admin-ajax.php'), 104 106 'i18n_select_city_text' => esc_attr__( 'Select a city...', 'cod24-shipping' ) … … 133 135 'label' => esc_attr__('Carton Size', 'cod24-shipping'), 134 136 'first_option' => esc_attr__('Select the size...','cod24-shipping'), 135 'options' => COD24_API::get_carton_sizes() 137 'options' => COD24_Tipax_API::get_carton_sizes() 138 ), 139 'dimension' => array( 140 'label' => esc_attr__('Dimension (Tipax)', 'cod24-shipping'), 141 'length_placeholder' => esc_attr__('Length', 'cod24-shipping'), 142 'width_placeholder' => esc_attr__('Width', 'cod24-shipping'), 143 'height_placeholder' => esc_attr__('Height', 'cod24-shipping') 136 144 ), 137 145 'change_status_text' => esc_attr__('Change Status of COD24 Panel','cod24-shipping'), … … 241 249 $state_key = $key == 'billing_city' ? 'billing_state' : 'shipping_state'; 242 250 $current_sc = WC()->checkout->get_value( $state_key ) ? WC()->checkout->get_value( $state_key ) : get_user_meta( get_current_user_id(), 'billing_state', true); 243 251 $shipping_method = WC()->checkout->get_value('shipping_method') ? WC()->checkout->get_value('shipping_method')[0] : ''; 252 244 253 // Get country cities 245 if( !empty( $current_sc ) ) 246 $cities = COD24_API::get_cities( $current_sc ); 254 if( isset( $shipping_method ) && !empty( $shipping_method ) && strstr($shipping_method, 'cod24_tipax') ) 255 { 256 if( !empty( $current_sc ) ) 257 $cities = COD24_Tipax_API::get_cities( $current_sc ); 258 else 259 $cities = COD24_Tipax_API::get_cities( 'THR' ); 260 } 247 261 else 248 $cities = COD24_API::get_cities( 'THR' ); 249 262 { 263 if( !empty( $current_sc ) ) 264 $cities = COD24_API::get_cities( $current_sc ); 265 else 266 $cities = COD24_API::get_cities( 'THR' ); 267 } 268 250 269 if ( is_array( $cities ) ) { 251 270 … … 305 324 return $fields; 306 325 } 307 308 326 309 327 /** 310 328 * Woocommerce cart shipping packages … … 354 372 } 355 373 } 356 357 // If free shipping is available and specific conditions are met, hide other rates358 if ($free_shipping_available) {359 foreach ($rates as $rate_id => $rate) {360 if ('free_shipping' !== $rate->method_id) {361 unset($rates[$rate_id]); // Remove other shipping methods362 }363 }364 }365 374 366 375 // hide cod when shipping cost delivery is required … … 377 386 * @return void 378 387 */ 379 public function checkout_save_ total_weight_meta( $order_id ) {388 public function checkout_save_cod24_meta( $order_id ) { 380 389 381 390 $order = new \WC_Order( $order_id ); 391 $total_weight = 0; 392 $shipping_type = ''; 393 $cod24_data = array(); 382 394 383 395 if ( $order->get_total() > 100 ) { // Define your condition here 384 $total_weight = 0;396 385 397 foreach ($order->get_items() as $item) { 386 398 if ($item['product_id'] > 0) … … 393 405 } 394 406 } 395 $order->update_meta_data( '_custom_total_weight', $total_weight ); 396 $order->save(); 397 } 398 407 } 408 409 // Get shipping method from order 410 $shipping_methods = $order->get_items('shipping'); 411 412 $shipping_cost = 0; 413 foreach ($shipping_methods as $shipping_item) { 414 // Check the shipping method ID 415 $shipping_method_id = $shipping_item->get_method_id(); 416 417 if ($shipping_method_id === 'cod24_tipax') { 418 $shipping_cost = $shipping_item->get_total(); 419 $shipping_type = 'tipax' ; 420 } elseif ($shipping_method_id === 'cod24_special' || $shipping_method_id === 'cod24_pishtaz') { 421 $shipping_type = 'post'; 422 } 423 } 424 425 $cod24_info = array( 426 'total_weight' => ( $total_weight > 0 ) ? $total_weight : '', 427 'shipping_type' => ( !empty( $shipping_type ) ) ? $shipping_type : 'post', 428 'serial' => '', 429 'barcode' => '', 430 'data' => '' 431 ); 432 433 if( $shipping_type == 'tipax' && $shipping_cost == 0 ) 434 $order->update_meta_data( '_is_shipping_cost_on_delivery', 'yes' ); 435 436 $order->update_meta_data( '_cod24_info', $cod24_info ); 437 $order->save(); 399 438 } 400 439 … … 421 460 $order_id = ( get_class($post_or_order_object) === 'WP_Post' ) ? $post_or_order_object->ID : $post_or_order_object->get_id(); 422 461 $order = wc_get_order( $order_id ); 423 $order_cod24_serial = $order->get_meta('_cod24_serial', true) ? $order->get_meta('_cod24_serial', true) : '';424 $order_cod24_ barcode = $order->get_meta('_cod24_barcode', true) ? $order->get_meta('_cod24_barcode', true) : '';462 463 $order_cod24_info = $order->get_meta('_cod24_info', true) ? $order->get_meta('_cod24_info', true) : ''; 425 464 $order_cod24_status = $order->get_meta('_cod24_last_status', true) ? $order->get_meta('_cod24_last_status', true) : ''; 426 $order_non_standard_package = $order->get_meta('_cod24_non_standard_package', true) ? $order->get_meta('_cod24_non_standard_package', true) : '';427 $order_carton_size = $order->get_meta('_cod24_carton_size', true) ? $order->get_meta('_cod24_carton_size', true) : '';428 $order_content_parcel = $order->get_meta('_cod24_content_parcel', true) ? $order->get_meta('_cod24_content_parcel', true) : '';429 465 $order_is_shcod = $order->get_meta('_is_shipping_cost_on_delivery', true) ? $order->get_meta('_is_shipping_cost_on_delivery', true) : ''; 430 $order_custom_total_weight = $order->get_meta('_custom_total_weight', true) ? $order->get_meta('_custom_total_weight', true) : ''; 466 $weight_unit = get_option('woocommerce_weight_unit'); 467 $dimension_unit = get_option('woocommerce_dimension_unit'); 431 468 ?> 432 469 <form id="order_barcode_form" method="post" action=""> 433 <?php $weight_unit = get_option('woocommerce_weight_unit'); ?> 434 <div class="cod24-meta-fields" style="margin-bottom:10px"> 435 <div class="label" style="margin-bottom:10px"><label for="custom_total_weight"><?php esc_attr_e('Total weight of order', 'cod24-shipping'); ?> (<?php echo esc_attr( $weight_unit ); ?>)</label></div> 436 <input type="text" class="postbox custom_total_weight" id="custom_total_weight" style="margin-bottom:0px" name="total_weight" value="<?php echo esc_attr( $order_custom_total_weight ); ?>" /> 470 <div class="cod24-shipping-type" style="margin-bottom:10px"> 471 <div class="label" style="margin-bottom:10px"><label for="shipping_type"><?php esc_attr_e('Shipping Type', 'cod24-shipping'); ?></label></div> 472 <select name="shipping_type" id="shipping_type" class="postbox shipping_type" style="margin-bottom:10px" disabled> 473 <option value="none"><?php esc_attr_e('Select the shipping type...','cod24-shipping'); ?></option> 474 <option value="post" <?php if( !empty( $order_cod24_info ) ) selected( 'post', $order_cod24_info['shipping_type'] ); ?>><?php esc_attr_e('Post', 'cod24-shipping'); ?></option> 475 <option value="tipax" <?php if( !empty( $order_cod24_info ) ) selected( 'tipax', $order_cod24_info['shipping_type'] ); ?>><?php esc_attr_e('Tipax', 'cod24-shipping'); ?></option> 476 </select> 437 477 </div> 438 <div class="cod24-meta-fields" style="margin-bottom:10px"> 439 <input type="checkbox" class="postbox non_standard_package" id="non_standard_package" style="margin-bottom:0px" name="non_standard_package" value="yes" <?php checked( 'yes', $order_non_standard_package ); ?>/> 440 <label for="non_standard_package"><?php esc_attr_e('This order is a non-standard package', 'cod24-shipping'); ?></label> 441 <div class="description"><?php esc_attr_e('If the package weight is 2 kg or more, be sure to checked the non-standard option.', 'cod24-shipping'); ?></div> 442 </div> 443 <div class="cod24-meta-fields" style="margin-bottom:10px"> 444 <div class="label" style="margin-bottom:10px"><label for="carton_size"><?php esc_attr_e('Carton Size', 'cod24-shipping'); ?></label></div> 445 <select name="carton_size" id="carton_size" class="postbox carton_size" style="margin-bottom:10px"> 446 <option value="none"><?php esc_attr_e('Select the size...','cod24-shipping'); ?></option> 447 <?php foreach(COD24_API::get_carton_sizes() as $key => $carton_item) : ?> 448 <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $order_carton_size ); ?>><?php echo esc_attr( $carton_item ); ?></option> 449 <?php endforeach; ?> 450 </select> 451 <div class="description"><?php esc_attr_e('According to the contract of the post company, be sure to choose the size of the parcel.','cod24-shipping'); ?></div> 452 </div> 453 <div class="cod24-meta-fields" style="margin-bottom:10px"> 454 <div class="label" style="margin-bottom:10px"><label for="content_parcel"><?php esc_attr_e('Parcel Content', 'cod24-shipping'); ?></label></div> 455 <textarea name="content_parcel" class="postbox content_parcel" id="content_parcel" rows="5"><?php echo wp_kses_post( $order_content_parcel ); ?></textarea> 456 </div> 478 <!-- post section --> 479 <div class="cod24-post-section <?php if( !empty( $order_cod24_info ) && isset( $order_cod24_info['shipping_type'] ) && $order_cod24_info['shipping_type'] == 'post' ) echo 'active'; ?>"> 480 <div class="cod24-meta-fields" style="margin-bottom:10px"> 481 <div class="label" style="margin-bottom:10px"><label for="post_custom_total_weight"><?php esc_attr_e('Total weight of order', 'cod24-shipping'); ?> (<?php echo esc_attr( $weight_unit ); ?>)</label></div> 482 <input type="text" class="postbox post_custom_total_weight" id="post_custom_total_weight" style="margin-bottom:0px" name="post_custom_total_weight" value="<?php if( !empty( $order_cod24_info ) && isset( $order_cod24_info['total_weight'] ) && !empty( $order_cod24_info['total_weight'] ) ) echo esc_attr( $order_cod24_info['total_weight'] ); ?>" /> 483 </div> 484 <div class="cod24-meta-fields" style="margin-bottom:10px"> 485 <input type="checkbox" class="postbox post_non_standard_package" id="post_non_standard_package" style="margin-bottom:0px" name="post_non_standard_package" value="yes" <?php if( !empty( $order_cod24_info ) && isset( $order_cod24_info['non_standard_package'] ) && !empty( $order_cod24_info['non_standard_package'] ) ) checked( 'yes', $order_cod24_info['non_standard_package'] ); ?>/> 486 <label for="post_non_standard_package"><?php esc_attr_e('This order is a non-standard package', 'cod24-shipping'); ?></label> 487 <div class="description"><?php esc_attr_e('If the package weight is 2 kg or more, be sure to checked the non-standard option.', 'cod24-shipping'); ?></div> 488 </div> 489 <div class="cod24-meta-fields" style="margin-bottom:10px"> 490 <div class="label" style="margin-bottom:10px"><label for="carton_size"><?php esc_attr_e('Carton Size', 'cod24-shipping'); ?></label></div> 491 <select name="carton_size" id="carton_size" class="postbox carton_size" style="margin-bottom:10px"> 492 <option value="none"><?php esc_attr_e('Select the size...','cod24-shipping'); ?></option> 493 <?php foreach(COD24_API::get_carton_sizes() as $key => $carton_item) : ?> 494 <option value="<?php echo esc_attr( $key ); ?>" <?php if( isset( $order_cod24_info['carton_size'] ) && !empty( $order_cod24_info['carton_size'] ) ) selected( $key, $order_cod24_info['carton_size'] ); ?>><?php echo esc_attr( $carton_item ); ?></option> 495 <?php endforeach; ?> 496 </select> 497 <div class="description"><?php esc_attr_e('According to the contract of the post company, be sure to choose the size of the parcel.','cod24-shipping'); ?></div> 498 </div> 499 <div class="cod24-meta-fields" style="margin-bottom:10px"> 500 <div class="label" style="margin-bottom:10px"><label for="content_parcel"><?php esc_attr_e('Parcel Content', 'cod24-shipping'); ?></label></div> 501 <textarea name="content_parcel" class="postbox content_parcel" id="content_parcel" rows="5"><?php if( isset( $order_cod24_info['content_parcel'] ) && !empty( $order_cod24_info['content_parcel'] ) ) echo wp_kses_post( $order_cod24_info['content_parcel'] ); ?></textarea> 502 </div> 503 </div> 504 <!-- tipax section --> 505 <div class="cod24-tipax-section <?php if( !empty( $order_cod24_info ) && isset( $order_cod24_info['shipping_type'] ) && $order_cod24_info['shipping_type'] == 'tipax' ) echo 'active'; ?>"> 506 <div class="cod24-meta-fields" style="margin-bottom:10px"> 507 <div class="label" style="margin-bottom:10px"><label for="tipax_custom_total_weight"><?php esc_attr_e('Total weight of order', 'cod24-shipping'); ?> (<?php echo esc_attr( $weight_unit ); ?>)</label></div> 508 <input type="text" class="postbox tipax_custom_total_weight" id="tipax_custom_total_weight" style="margin-bottom:0px" name="tipax_custom_total_weight" value="<?php if( !empty( $order_cod24_info ) && isset( $order_cod24_info['shipping_type'] ) && !empty( $order_cod24_info['total_weight'] ) ) echo esc_attr( $order_cod24_info['total_weight'] ); ?>" /> 509 </div> 510 <div class="cod24-meta-fields" style="margin-bottom:10px"> 511 <div class="label" style="margin-bottom:10px"><label for="tipax_carton_size"><?php esc_attr_e('Carton Size', 'cod24-shipping'); ?></label></div> 512 <select name="tipax_carton_size" id="tipax_carton_size" class="postbox tipax_carton_size" style="margin-bottom:10px"> 513 <option value="none"><?php esc_attr_e('Select the size...','cod24-shipping'); ?></option> 514 <?php foreach(COD24_Tipax_API::get_carton_sizes() as $key => $carton_item) : ?> 515 <?php 516 $selected_element = ''; 517 $dimension_elements = explode("-", $key ); 518 if( count( $dimension_elements ) == 3 ) 519 { 520 if( !empty( $order_cod24_info ) && isset( $order_cod24_info['total_dimension'] ) && !empty( $order_cod24_info['total_dimension'] ) ) 521 { 522 if( $order_cod24_info['total_dimension']['length'] == $dimension_elements[0] && $order_cod24_info['total_dimension']['width'] == $dimension_elements[1] && $order_cod24_info['total_dimension']['height'] == $dimension_elements[2] ) 523 { 524 $selected_element = $key; 525 } 526 } 527 } 528 else 529 { 530 $selected_element = 'other'; 531 } 532 ?> 533 <?php if( count( $dimension_elements ) == 3 ) : ?> 534 <option data-length="<?php if( isset( $dimension_elements ) && !empty( $dimension_elements ) ) echo esc_attr( $dimension_elements[0] ); ?>" data-width="<?php if( isset( $dimension_elements ) && !empty( $dimension_elements ) ) echo esc_attr( $dimension_elements[1] ); ?>" data-height="<?php if( isset( $dimension_elements ) && !empty( $dimension_elements ) ) echo esc_attr( $dimension_elements[2] ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $selected_element ); ?>><?php echo esc_attr( $carton_item ); ?></option> 535 <?php else : ?> 536 <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $selected_element ); ?>><?php echo esc_attr( $carton_item ); ?></option> 537 <?php endif; ?> 538 <?php endforeach; ?> 539 </select> 540 <div class="description"><?php esc_attr_e('According to the contract of the post company, be sure to choose the size of the parcel.','cod24-shipping'); ?></div> 541 </div> 542 <div class="cod24-meta-fields" style="margin-bottom:10px"> 543 <div class="label" style="margin-bottom:10px"><label for="custom_total_dimension"><?php esc_attr_e('Total dimension of order', 'cod24-shipping'); ?> (<?php echo esc_attr( $dimension_unit ); ?>)</label></div> 544 <div class="cod24-dimension-fields"> 545 <input type="text" class="dimension-length" id="custom_total_dimension" style="margin-bottom:0px" name="custom_total_dimension[length]" placeholder="<?php echo esc_attr__('Length','cod24-shipping'); ?>" value="<?php if( !empty( $order_cod24_info ) && isset( $order_cod24_info['total_dimension'] ) && !empty( $order_cod24_info['total_dimension'] ) ) echo esc_attr( $order_cod24_info['total_dimension']['length'] ); ?>" /> 546 <input type="text" class="dimension-width" style="margin-bottom:0px" name="custom_total_dimension[width]" placeholder="<?php echo esc_attr__('Width','cod24-shipping'); ?>" value="<?php if( !empty( $order_cod24_info ) && isset( $order_cod24_info['total_dimension'] ) && !empty( $order_cod24_info['total_dimension'] ) ) echo esc_attr( $order_cod24_info['total_dimension']['width'] ); ?>" /> 547 <input type="text" class="dimension-height" style="margin-bottom:0px" name="custom_total_dimension[height]" placeholder="<?php echo esc_attr__('Height','cod24-shipping'); ?>" value="<?php if( !empty( $order_cod24_info ) && isset( $order_cod24_info['total_dimension'] ) && !empty( $order_cod24_info['total_dimension'] ) ) echo esc_attr( $order_cod24_info['total_dimension']['height'] ); ?>" /> 548 </div> 549 </div> 550 <div class="cod24-meta-fields" style="margin-bottom:10px"> 551 <input type="checkbox" class="postbox tipax_non_standard_package" id="tipax_non_standard_package" style="margin-bottom:0px" name="tipax_non_standard_package" value="yes" <?php if( !empty( $order_cod24_info ) && isset( $order_cod24_info['non_standard_package'] ) && !empty( $order_cod24_info['non_standard_package'] ) ) checked( 'yes', $order_cod24_info['non_standard_package'] ); ?>/> 552 <label for="tipax_non_standard_package"><?php esc_attr_e('This order is a non-standard package', 'cod24-shipping'); ?></label> 553 <div class="description"><?php esc_attr_e('If the package weight is 2 kg or more, be sure to checked the non-standard option.', 'cod24-shipping'); ?></div> 554 </div> 555 <div class="cod24-meta-fields" style="margin-bottom:10px"> 556 <div class="label" style="margin-bottom:10px"><label for="pack_type"><?php esc_attr_e('Pack Type', 'cod24-shipping'); ?></label></div> 557 <select name="pack_type" id="pack_type" class="postbox pack_type" style="margin-bottom:10px"> 558 <option value="none"><?php esc_attr_e('Select the pack type...','cod24-shipping'); ?></option> 559 <?php foreach(COD24_Tipax_API::get_pack_type_list() as $key => $pack_type_item) : ?> 560 <option value="<?php echo esc_attr( $key ); ?>" <?php if( !empty( $order_cod24_info ) && isset( $order_cod24_info['pack_type'] ) && !empty( $order_cod24_info['pack_type'] ) ) selected( $key, $order_cod24_info['pack_type'] ); ?>><?php echo esc_attr( $pack_type_item ); ?></option> 561 <?php endforeach; ?> 562 </select> 563 </div> 564 <div class="cod24-meta-fields" style="margin-bottom:10px"> 565 <div class="label" style="margin-bottom:10px"><label for="package_content"><?php esc_attr_e('Package Content', 'cod24-shipping'); ?></label></div> 566 <select name="package_content" id="package_content" class="postbox package_content" style="margin-bottom:10px"> 567 <option value="none"><?php esc_attr_e('Select the package content...','cod24-shipping'); ?></option> 568 <?php foreach(COD24_Tipax_API::get_package_content_list() as $key => $package_content_item) : ?> 569 <option value="<?php echo esc_attr( $key ); ?>" <?php if( !empty( $order_cod24_info ) && isset( $order_cod24_info['package_content'] ) && !empty( $order_cod24_info['package_content'] ) ) selected( $key, $order_cod24_info['package_content'] ); ?>><?php echo esc_attr( $package_content_item ); ?></option> 570 <?php endforeach; ?> 571 </select> 572 </div> 573 <div class="cod24-meta-fields" style="margin-bottom:10px"> 574 <div class="label" style="margin-bottom:10px"><label for="pickup_type"><?php esc_attr_e('Pickup Type', 'cod24-shipping'); ?></label></div> 575 <select name="pickup_type" id="pickup_type" class="postbox pickup_type" style="margin-bottom:10px"> 576 <option value="none"><?php esc_attr_e('Select the pickup type...','cod24-shipping'); ?></option> 577 <?php foreach(COD24_Tipax_API::get_pickup_type_list() as $key => $pickup_type_item) : ?> 578 <option value="<?php echo esc_attr( $key ); ?>" <?php if( !empty( $order_cod24_info ) && isset( $order_cod24_info['pickup_type'] ) && !empty( $order_cod24_info['pickup_type'] ) ) selected( $key, $order_cod24_info['pickup_type'] ); ?>><?php echo esc_attr( $pickup_type_item ); ?></option> 579 <?php endforeach; ?> 580 </select> 581 </div> 582 <div class="cod24-meta-fields" style="margin-bottom:10px"> 583 <div class="label" style="margin-bottom:10px"><label for="distribution_type"><?php esc_attr_e('Distribution Type', 'cod24-shipping'); ?></label></div> 584 <select name="distribution_type" id="distribution_type" class="postbox distribution_type" style="margin-bottom:10px"> 585 <option value="none"><?php esc_attr_e('Select the distribution type...','cod24-shipping'); ?></option> 586 <?php foreach(COD24_Tipax_API::get_distribution_type_list() as $key => $distribution_type_item) : ?> 587 <option value="<?php echo esc_attr( $key ); ?>" <?php if( !empty( $order_cod24_info ) && isset( $order_cod24_info['distribution_type'] ) && !empty( $order_cod24_info['distribution_type'] ) ) selected( $key, $order_cod24_info['distribution_type'] ); ?>><?php echo esc_attr( $distribution_type_item ); ?></option> 588 <?php endforeach; ?> 589 </select> 590 </div> 591 </div> 592 457 593 <div style="margin-bottom:10px"> 458 594 <div class="label" style="margin-bottom:10px"><label for="cod24_status"><?php esc_attr_e('Change COD24 Status', 'cod24-shipping'); ?></label></div> … … 460 596 <option value="none"><?php esc_attr_e('Select the status...','cod24-shipping'); ?></option> 461 597 <option value="cod24-add" <?php selected( 'cod24-add', $order_cod24_status ); ?>><?php esc_attr_e('Add Order', 'cod24-shipping'); ?></option> 462 <option value="cod24-suspend" <?php selected( 'cod24-suspend', $order_cod24_status ); ?> ><?php esc_attr_e('Suspend Order', 'cod24-shipping'); ?></option>598 <option value="cod24-suspend" <?php selected( 'cod24-suspend', $order_cod24_status ); ?> <?php if( !empty( $order_cod24_info ) && isset( $order_cod24_info['shipping_type'] ) && !empty( $order_cod24_info['shipping_type'] ) && $order_cod24_info['shipping_type'] == 'tipax' ) echo 'disabled="disabled"'; ?>><?php esc_attr_e('Suspend Order', 'cod24-shipping'); ?></option> 463 599 <option value="cod24-ready-send" <?php selected( 'cod24-ready-send', $order_cod24_status ); ?>><?php esc_attr_e('Ready To Send Order', 'cod24-shipping'); ?></option> 464 600 <option value="cod24-cancel" <?php selected( 'cod24-cancel', $order_cod24_status ); ?>><?php esc_attr_e('Cancel Order', 'cod24-shipping'); ?></option> … … 466 602 <button type="button" class="button cod24_change_status" name="cod24_change_status"><?php esc_attr_e('Send To Panel', 'cod24-shipping'); ?></button> 467 603 </div> 468 <p class="serial"><?php esc_attr_e('Serial:', 'cod24-shipping'); ?> <strong><?php if(!empty($order_cod24_ serial)) echo esc_attr( $order_cod24_serial); else echo "-"; ?></strong></p>469 <p class="barcode"><?php esc_attr_e(' Post Barcode:', 'cod24-shipping'); ?> <strong><?php if(!empty($order_cod24_barcode)) echo esc_attr( $order_cod24_barcode); else echo "-"; ?></strong></p>470 <p class="shcod"><?php esc_attr_e('Shipping cost at the destination:', 'cod24-shipping'); ?> <strong><?php if( !empty($order_is_shcod)) esc_attr_e('Yes', 'cod24-shipping'); else esc_attr_e('No', 'cod24-shipping'); ?></strong></p>604 <p class="serial"><?php esc_attr_e('Serial:', 'cod24-shipping'); ?> <strong><?php if(!empty($order_cod24_info['serial'])) echo esc_attr( $order_cod24_info['serial'] ); else echo "-"; ?></strong></p> 605 <p class="barcode"><?php esc_attr_e('Barcode:', 'cod24-shipping'); ?> <strong><?php if(!empty( $order_cod24_info['barcode'] ) ) echo esc_attr( $order_cod24_info['barcode'] ); else echo "-"; ?></strong></p> 606 <p class="shcod"><?php esc_attr_e('Shipping cost at the destination:', 'cod24-shipping'); ?> <strong><?php if( !empty( $order_is_shcod ) ) esc_attr_e('Yes', 'cod24-shipping'); else esc_attr_e('No', 'cod24-shipping'); ?></strong></p> 471 607 <input type="hidden" class="order_barcode_nonce" name="order_barcode_nonce" value="<?php echo esc_attr( wp_create_nonce('order_barcode_nonce') ); ?>" /> 472 608 <input type="hidden" class="order_id" name="order_id" value="<?php echo esc_attr( $order->get_id() ); ?>" /> 473 <button type="button" class="button cod24_factorPreview" name="cod24_factorPreview" <?php if( empty($order_cod24_ serial) && empty($order_cod24_barcode)) echo 'disabled="disabled"'; ?>><?php echo esc_attr__('Print Factor', 'cod24-shipping'); ?></button>609 <button type="button" class="button cod24_factorPreview" name="cod24_factorPreview" <?php if( empty($order_cod24_info['serial']) && empty($order_cod24_info['barcode'])) echo 'disabled="disabled"'; ?>><?php echo esc_attr__('Print Factor', 'cod24-shipping'); ?></button> 474 610 </form> 475 611 <?php 476 612 } 477 613 478 614 /** 479 * Save c ustom total weight615 * Save cod24 fields 480 616 */ 481 public function save_order_c ustom_total_weight( $order_id )617 public function save_order_cod24_fields( $order_id ) 482 618 { 483 if ( ! isset( $_POST['total_weight'] ) ) { 484 return; 485 } 486 487 if( isset( $_POST['total_weight'] ) && !empty( $_POST['total_weight'] ) ) 488 { 489 $user_total_weight = floatval( sanitize_text_field( $_POST['total_weight'] ) ); 490 $order = wc_get_order( $order_id ); 491 $order->update_meta_data( '_custom_total_weight', $user_total_weight ); 492 $order->save(); 493 } 619 $order = wc_get_order( $order_id ); 620 $old_cod24_info = $order->get_meta('_cod24_info', true); 621 622 $shipping_types = array( 'post', 'tipax' ); 623 if( in_array( $old_cod24_info['shipping_type'], $shipping_types ) ) 624 { 625 $cod24_info = array(); 626 $cod24_info['shipping_type'] = $old_cod24_info['shipping_type']; 627 628 if( $old_cod24_info['shipping_type'] == 'post' ) 629 { 630 631 // check total weight 632 $cod24_info['total_weight'] = floatval( sanitize_text_field( $_POST['post_custom_total_weight'] ) ); 633 634 // check non standard package 635 if( isset( $_POST['post_non_standard_package'] ) && $_POST['post_non_standard_package'] == 'yes' ) 636 $cod24_info['non_standard_package'] = 'yes'; 637 else 638 $cod24_info['non_standard_package'] = 'no'; 639 640 // check carton size 641 $carton_sizes = COD24_API::get_carton_sizes(); 642 $user_carton_size = sanitize_text_field( $_POST['carton_size'] ); 643 if( in_array( $user_carton_size, array_keys( $carton_sizes ) ) ) 644 { 645 $cod24_info['carton_size'] = $user_carton_size; 646 } 647 648 // check content parcel 649 if( isset( $_POST['content_parcel'] ) && !empty( $_POST['content_parcel'] ) ) 650 { 651 $cod24_info['content_parcel'] = sanitize_textarea_field( $_POST['content_parcel'] ); 652 } 653 } 654 elseif( $old_cod24_info['shipping_type'] == 'tipax' ) 655 { 656 // check total weight 657 $cod24_info['total_weight'] = floatval( sanitize_text_field( $_POST['tipax_custom_total_weight'] ) ); 658 659 // check custom dimension 660 if( isset( $_POST['custom_total_dimension'] ) && ! empty( $_POST['custom_total_dimension'] ) ) 661 { 662 $cod24_info['total_dimension'] = array( 663 'length' => floatval( sanitize_text_field( $_POST['custom_total_dimension']['length'] ) ), 664 'width' => floatval( sanitize_text_field( $_POST['custom_total_dimension']['width'] ) ), 665 'height' => floatval( sanitize_text_field( $_POST['custom_total_dimension']['height'] ) ) 666 ); 667 } 668 669 // check non standard package 670 if( isset( $_POST['tipax_non_standard_package'] ) && $_POST['tipax_non_standard_package'] == 'yes' ) 671 $cod24_info['non_standard_package'] = 'yes'; 672 else 673 $cod24_info['non_standard_package'] = 'no'; 674 675 // check pack type 676 $pack_types = COD24_Tipax_API::get_pack_type_list(); 677 $user_pack_type = sanitize_text_field( $_POST['pack_type'] ); 678 if( in_array( $user_pack_type, array_keys( $pack_types ) ) ) 679 { 680 $cod24_info['pack_type'] = $user_pack_type; 681 } 682 683 // check package content 684 $package_content_list = COD24_Tipax_API::get_package_content_list(); 685 $user_package_content = sanitize_text_field( $_POST['package_content'] ); 686 if( in_array( $user_package_content, array_keys( $package_content_list ) ) ) 687 { 688 $cod24_info['package_content'] = $user_package_content; 689 } 690 691 // check pickup type 692 $pickup_types = COD24_Tipax_API::get_pickup_type_list(); 693 $user_pickup_type = sanitize_text_field( $_POST['pickup_type'] ); 694 if( in_array( $user_pickup_type, array_keys( $pickup_types ) ) ) 695 { 696 $cod24_info['pickup_type'] = $user_pickup_type; 697 } 698 699 // check pickup type 700 $distribution_types = COD24_Tipax_API::get_distribution_type_list(); 701 $user_distribution_type = sanitize_text_field( $_POST['distribution_type'] ); 702 if( in_array( $user_distribution_type, array_keys( $distribution_types ) ) ) 703 { 704 $cod24_info['distribution_type'] = $user_distribution_type; 705 } 706 707 $cod24_info['serial'] = ''; 708 $cod24_info['barcode'] = ''; 709 } 710 711 $order->update_meta_data( '_cod24_info', $cod24_info ); 712 $order->save(); 713 } 494 714 } 495 715 496 /**497 * Save non standard package498 */499 public function save_order_non_standard_package( $order_id )500 {501 if ( ! isset( $_POST['non_standard_package'] ) ) {502 return;503 }504 505 if( isset( $_POST['non_standard_package'] ) && !empty( $_POST['non_standard_package'] ) )506 {507 $order = wc_get_order( $order_id );508 if( isset( $_POST['non_standard_package'] ) && sanitize_text_field( $_POST['non_standard_package'] ) == 'yes' )509 $order->update_meta_data( '_cod24_non_standard_package', 'yes' );510 else511 $order->update_meta_data( '_cod24_non_standard_package', 'no' );512 $order->save();513 }514 }515 516 /**517 * Save carton size518 */519 public function save_order_carton_size( $order_id )520 {521 if ( ! isset( $_POST['carton_size'] ) ) {522 return;523 }524 525 if( isset( $_POST['carton_size'] ) && !empty( $_POST['carton_size'] ) && sanitize_text_field( $_POST['carton_size'] ) != 'none' )526 {527 $order = wc_get_order( $order_id );528 $carton_sizes = COD24_API::get_carton_sizes();529 $user_carton_size = sanitize_text_field( $_POST['carton_size'] );530 if( in_array( $user_carton_size, array_keys( $carton_sizes ) ) )531 {532 $order->update_meta_data( '_cod24_carton_size', $user_carton_size );533 }534 else535 {536 $order->update_meta_data( '_cod24_carton_size', $user_carton_size );537 }538 $order->save();539 }540 }541 542 /**543 * Save content parcel544 */545 public function save_order_content_parcel( $order_id )546 {547 if ( ! isset( $_POST['content_parcel'] ) ) {548 return;549 }550 551 if( isset( $_POST['content_parcel'] ) && !empty( $_POST['content_parcel'] ) )552 {553 $order = wc_get_order( $order_id );554 $user_content_parcel = wp_kses_post( $_POST['content_parcel'] );555 $order->update_meta_data( '_cod24_content_parcel', $user_content_parcel );556 $order->save();557 }558 }559 560 716 /** 561 717 * Ajax handler for receive serial … … 567 723 { 568 724 $result = array(); 725 $cod24_info = array(); 569 726 if ( wp_verify_nonce( sanitize_text_field( wp_unslash ( $_POST['order_barcode_nonce'] ) ) , 'order_barcode_nonce' ) ) 570 727 { 571 728 $order_id = intval( $_REQUEST['order_id'] ); 572 $custom_total_weight = floatval( $_REQUEST['total_weight'] ); // user enter custom total weight573 729 $cod24_new_status = sanitize_text_field( $_REQUEST['cod24_status'] ); // user enter custom total weight 574 730 … … 576 732 if( !empty( $order_id ) && absint( $order_id ) > 0 ) 577 733 { 578 $order = wc_get_order( $order_id ); 579 580 // update custom total weight 581 $custom_total_weight_valid = 0; 582 if( $custom_total_weight > 0 ) 583 { 584 $order->update_meta_data( '_custom_total_weight', $custom_total_weight ); 585 $custom_total_weight_valid = 1; 586 } 587 588 // update non standard package 589 if( isset( $_REQUEST['non_standard_package'] ) && $_REQUEST['non_standard_package'] == 'yes' ) 590 $order->update_meta_data( '_cod24_non_standard_package', 'yes' ); 591 else 592 $order->update_meta_data( '_cod24_non_standard_package', 'no' ); 593 594 // update carton size 595 $user_carton_size = sanitize_text_field( $_REQUEST['carton_size'] ); 596 $carton_sizes = COD24_API::get_carton_sizes(); 597 if( in_array( $user_carton_size, array_keys( $carton_sizes ) ) ) 598 { 599 $order->update_meta_data( '_cod24_carton_size', $user_carton_size ); 600 } 601 else 602 { 603 $order->update_meta_data( '_cod24_carton_size', 0 ); 604 } 605 606 // update content parcel 607 if( isset( $_REQUEST['content_parcel'] ) && !empty( $_REQUEST['content_parcel'] ) ) 608 { 609 $order->update_meta_data( '_cod24_content_parcel', wp_kses_post( $_REQUEST['content_parcel'] ) ); 610 } 734 $order = wc_get_order( $order_id ); 735 $old_cod24_info = ( $order->get_meta('_cod24_info', true ) ) ? $order->get_meta('_cod24_info', true ) : array(); 736 $cod24_last_status = $order->get_meta('_cod24_last_status', true ); 737 738 $shipping_types = array( 'post', 'tipax' ); 739 if( in_array( $old_cod24_info['shipping_type'], $shipping_types ) ) 740 { 741 $cod24_info['shipping_type'] = $old_cod24_info['shipping_type']; 742 $cod24_info['serial'] = ( !empty( $old_cod24_info['serial'] ) ) ? $old_cod24_info['serial'] : ''; 743 $cod24_info['barcode'] = ( !empty( $old_cod24_info['barcode'] ) ) ? $old_cod24_info['barcode'] : ''; 744 745 if( $old_cod24_info['shipping_type'] == 'post' ) 746 { 747 // check total weight 748 $cod24_info['total_weight'] = floatval( sanitize_text_field( wp_unslash( $_REQUEST['post_custom_total_weight'] ) ) ); 749 750 // check non standard package 751 if( isset( $_POST['post_non_standard_package'] ) && $_POST['post_non_standard_package'] == 'yes' ) 752 $cod24_info['non_standard_package'] = 'yes'; 753 else 754 $cod24_info['non_standard_package'] = 'no'; 755 756 // check carton size 757 $carton_sizes = COD24_API::get_carton_sizes(); 758 $user_carton_size = sanitize_text_field( $_POST['carton_size'] ); 759 if( in_array( $user_carton_size, array_keys( $carton_sizes ) ) ) 760 { 761 $cod24_info['carton_size'] = $user_carton_size; 762 } 763 764 // check content parcel 765 if( isset( $_POST['content_parcel'] ) && !empty( $_POST['content_parcel'] ) ) 766 { 767 $cod24_info['content_parcel'] = sanitize_textarea_field( $_POST['content_parcel'] ); 768 } 769 } 770 elseif( $old_cod24_info['shipping_type'] == 'tipax' ) 771 { 772 // check total weight 773 $cod24_info['total_weight'] = floatval( sanitize_text_field( $_POST['tipax_custom_total_weight'] ) ); 774 775 // check custom dimension 776 if( isset( $_POST['custom_total_dimension'] ) && ! empty( $_POST['custom_total_dimension'] ) ) 777 { 778 $cod24_info['total_dimension'] = array( 779 'length' => floatval( sanitize_text_field( $_POST['custom_total_dimension']['length'] ) ), 780 'width' => floatval( sanitize_text_field( $_POST['custom_total_dimension']['width'] ) ), 781 'height' => floatval( sanitize_text_field( $_POST['custom_total_dimension']['height'] ) ) 782 ); 783 } 784 785 // check non standard package 786 if( isset( $_POST['tipax_non_standard_package'] ) && $_POST['tipax_non_standard_package'] == 'yes' ) 787 $cod24_info['non_standard_package'] = 'yes'; 788 else 789 $cod24_info['non_standard_package'] = 'no'; 790 791 // check pack type 792 $pack_types = COD24_Tipax_API::get_pack_type_list(); 793 $user_pack_type = sanitize_text_field( $_POST['pack_type'] ); 794 if( in_array( $user_pack_type, array_keys( $pack_types ) ) ) 795 { 796 $cod24_info['pack_type'] = $user_pack_type; 797 } 798 799 // check package content 800 $package_content_list = COD24_Tipax_API::get_package_content_list(); 801 $user_package_content = sanitize_text_field( $_POST['package_content'] ); 802 if( in_array( $user_package_content, array_keys( $package_content_list ) ) ) 803 { 804 $cod24_info['package_content'] = $user_package_content; 805 } 806 807 // check pickup type 808 $pickup_types = COD24_Tipax_API::get_pickup_type_list(); 809 $user_pickup_type = sanitize_text_field( $_POST['pickup_type'] ); 810 if( in_array( $user_pickup_type, array_keys( $pickup_types ) ) ) 811 { 812 $cod24_info['pickup_type'] = $user_pickup_type; 813 } 814 815 // check pickup type 816 $distribution_types = COD24_Tipax_API::get_distribution_type_list(); 817 $user_distribution_type = sanitize_text_field( $_POST['distribution_type'] ); 818 if( in_array( $user_distribution_type, array_keys( $distribution_types ) ) ) 819 { 820 $cod24_info['distribution_type'] = $user_distribution_type; 821 } 822 } 823 824 $order->update_meta_data( '_cod24_info', $cod24_info ); 825 } 611 826 612 827 $order->save(); 613 614 // check cod24 status 615 $cod24_serial = $order->get_meta('_cod24_serial', true ); 616 $cod24_barcode = $order->get_meta('_cod24_barcode', true ); 617 $cod24_last_status = $order->get_meta('_cod24_last_status', true ); 828 $cod24_info = $order->get_meta('_cod24_info', true ); 618 829 619 830 // If the new status is 'cod24-add' 620 if( $c ustom_total_weight_valid)831 if( $cod24_info['total_weight'] ) 621 832 { 622 833 if ( $cod24_new_status == 'cod24-add' && $cod24_last_status != 'cod24-add' ) 623 834 { 624 835 // Check if the weight post meta is empty 625 if ( empty( $c ustom_total_weight) )836 if ( empty( $cod24_info['total_weight'] ) ) 626 837 { 627 838 // Add an order note for admin … … 633 844 else 634 845 { 635 if( !empty( $cod24_ serial) )846 if( !empty( $cod24_info['serial'] ) ) 636 847 { 637 848 // Add an order note for admin … … 643 854 else 644 855 { 645 $result = COD24_API::add_order( $order_id ); 856 if( $cod24_info['shipping_type'] == 'tipax' ) 857 $result = COD24_Tipax_API::add_order( $order_id ); 858 else 859 $result = COD24_API::add_order( $order_id ); 646 860 647 861 if( !empty( $result['serial'] ) ) 648 862 { 649 863 // update serial 650 $order->update_meta_data( '_cod24_serial', $result['serial'] ); 864 $cod24_info['serial'] = $result['serial']; 865 $order->update_meta_data( '_cod24_info', $cod24_info ); 651 866 $order->save(); 652 867 … … 677 892 // Add an order note for admin 678 893 $order->add_order_note( 679 sprintf( esc_attr__( 'There is a problem when adding the order to the COD24 panel. Error: <br />%s', 'cod24-shipping' ), $errors ), /* translators: %s is the error from api */894 sprintf( esc_attr__( 'There is a problem when adding the order to the COD24 panel. Error: %s', 'cod24-shipping' ), $errors ), /* translators: %s is the error from api */ 680 895 0 // Private note for admin only 681 896 ); … … 714 929 else 715 930 { 716 if( empty( $cod24_ serial) )931 if( empty( $cod24_info['serial'] ) ) 717 932 { 718 933 // Add an order note for admin … … 724 939 else 725 940 { 726 $result = COD24_API::suspend_order( array( array( 'serial' => absint( $cod24_serial), 'idOrderShop' => (string) $order_id ) ) ); 727 728 if( !empty( $result[0]['barcode'] ) && $result[0]['isSuccess'] && $result[0]['code'] == 0 ) 729 { 730 // update barcode 731 $order->update_meta_data( '_cod24_barcode', $result[0]['barcode'] ); 732 $order->save(); 733 734 // Add an order note for user 735 $order->add_order_note( 736 sprintf( esc_attr__('The order successfully suspended in the COD24 panel. Post Barcode: %s', 'cod24-shipping' ), $result[0]['barcode'] ), 737 1 // Public note 738 ); 739 740 $order->update_status( 'cod24-suspend' ); 741 742 // update cod24 last status 743 $order->update_meta_data( '_cod24_last_status', 'cod24-suspend' ); 744 $order->save(); 745 } 746 else 747 { 748 if( !empty( $result[0]['code'] ) && !empty( $result[0]['message'] ) ) 749 { 750 // Add an order note for admin 751 $order->add_order_note( 752 sprintf( esc_attr__( 'There is a problem when suspending the order in the COD24 panel. Error: %1$s - %2$s', 'cod24-shipping' ), $result[0]['code'] , $result[0]['message'] ), 753 0 // Private note for admin only 754 ); 755 } 756 else 757 { 758 $order->add_order_note( 759 sprintf( esc_attr__( 'There is a problem when suspending the order in the COD24 panel.', 'cod24-shipping' ) ), 760 0 // Private note for admin only 761 ); 762 } 763 } 941 if( $cod24_info['shipping_type'] == 'post' ) // suspend order only for post shipping 942 { 943 $result = COD24_API::suspend_order( array( array( 'serial' => absint( $cod24_info['serial'] ), 'idOrderShop' => strval( $order_id ) ) ) ); 944 945 if( !empty( $result[0]['barcode'] ) && $result[0]['isSuccess'] && $result[0]['code'] == 0 ) 946 { 947 // update barcode 948 $cod24_info['barcode'] = $result[0]['barcode']; 949 $order->update_meta_data( '_cod24_info', $cod24_info ); 950 $order->save(); 951 952 // Add an order note for user 953 $order->add_order_note( 954 sprintf( esc_attr__('The order successfully suspended in the COD24 panel. Barcode: %s', 'cod24-shipping' ), $result[0]['barcode'] ), 955 1 // Public note 956 ); 957 958 $order->update_status( 'cod24-suspend' ); 959 960 // update cod24 last status 961 $order->update_meta_data( '_cod24_last_status', 'cod24-suspend' ); 962 $order->save(); 963 } 964 else 965 { 966 if( !empty( $result[0]['code'] ) && !empty( $result[0]['message'] ) ) 967 { 968 // Add an order note for admin 969 $order->add_order_note( 970 sprintf( esc_attr__( 'There is a problem when suspending the order in the COD24 panel. Error: %1$s - %2$s', 'cod24-shipping' ), $result[0]['code'] , $result[0]['message'] ), 971 0 // Private note for admin only 972 ); 973 } 974 elseif( !empty( $result['code'] ) && !empty( $result['message'] ) ) 975 { 976 // Add an order note for admin 977 $order->add_order_note( 978 sprintf( esc_attr__( 'There is a problem when suspending the order in the COD24 panel. Error: %1$s - %2$s', 'cod24-shipping' ), $result['code'] , $result['message'] ), 979 0 // Private note for admin only 980 ); 981 982 $error_message = sprintf( esc_attr__( 'There is a problem when suspending the order in the COD24 panel. Error: %1$s - %2$s', 'cod24-shipping' ), $result['code'] , $result['message'] ); 983 } 984 else 985 { 986 $order->add_order_note( 987 sprintf( esc_attr__( 'There is a problem when suspending the order in the COD24 panel.', 'cod24-shipping' ) ), 988 0 // Private note for admin only 989 ); 990 } 991 } 992 } 993 else 994 { 995 $order->add_order_note( 996 sprintf( esc_attr__( '"Suspend Order" is available only for the Post Shipping Method.', 'cod24-shipping' ) ), 997 0 // Private note for admin only 998 ); 999 } 764 1000 } 765 1001 } … … 767 1003 elseif ( $cod24_new_status == 'cod24-ready-send' && $cod24_last_status != 'cod24-ready-send' ) // If the new status is 'cod24-ready-send' 768 1004 { 769 // Check if the weight post meta is empty 770 if ( empty( $cod24_last_status ) || ( !empty( $cod24_last_status ) && $cod24_last_status != 'cod24-suspend' ) ) 771 { 772 // Add an order note for admin 773 $order->add_order_note( 774 esc_attr__( 'You should select the "Suspend Order" status first.', 'cod24-shipping' ), 775 0 // Private note for admin only 776 ); 777 } 778 else 779 { 780 if( empty( $cod24_barcode ) ) 781 { 782 // Add an order note for admin 783 $order->add_order_note( 784 esc_attr__( 'No Post Barcode registered for this order.', 'cod24-shipping' ), 785 0 // Private note for admin only 786 ); 787 } 788 else 789 { 790 $result = COD24_API::ready_to_send_order( array( array( 'serial' => absint( $cod24_serial ), 'idOrderShop' => (string) $order_id ) ) ); 791 1005 if( $cod24_info['shipping_type'] == 'post' ) 1006 { 1007 // Check if the weight post meta is empty 1008 if ( empty( $cod24_last_status ) || ( !empty( $cod24_last_status ) && $cod24_last_status != 'cod24-suspend' ) ) 1009 { 1010 // Add an order note for admin 1011 $order->add_order_note( 1012 esc_attr__( 'You should select the "Suspend Order" status first.', 'cod24-shipping' ), 1013 0 // Private note for admin only 1014 ); 1015 } 1016 else 1017 { 1018 if( empty( $cod24_info['barcode'] ) ) 1019 { 1020 // Add an order note for admin 1021 $order->add_order_note( 1022 esc_attr__( 'No Barcode registered for this order.', 'cod24-shipping' ), 1023 0 // Private note for admin only 1024 ); 1025 } 1026 else 1027 { 1028 $result = COD24_API::ready_to_send_order( array( array( 'serial' => absint( $cod24_info['serial'] ), 'idOrderShop' => strval( $order_id ) ) ) ); 1029 1030 if( $result[0]['isSuccess'] && $result[0]['code'] == 0 ) 1031 { 1032 // Add an order note for user 1033 $order->add_order_note( 1034 esc_attr__('The order status changed to "Ready To Send" in the COD24 panel successfully.', 'cod24-shipping' ), 1035 1 // Public note 1036 ); 1037 1038 $order->update_status( 'cod24-ready-send' ); 1039 1040 // update cod24 last status 1041 $order->update_meta_data( '_cod24_last_status', 'cod24-ready-send' ); 1042 $order->save(); 1043 } 1044 else 1045 { 1046 // Add an order note for admin 1047 if( !empty($result[0]['code']) && !empty( $result[0]['message'] ) ) 1048 { 1049 $order->add_order_note( 1050 sprintf( esc_attr__( 'There is a problem when changing the order status to "Ready To Send" in the COD24 panel. Error: %1$s - %2$s', 'cod24-shipping' ), $result[0]['code'] , $result[0]['message'] ), 1051 0 // Private note for admin only 1052 ); 1053 } 1054 else 1055 { 1056 $order->add_order_note( 1057 sprintf( esc_attr__( 'There is a problem when changing the order status to "Ready To Send" in the COD24 panel.', 'cod24-shipping' ) ), 1058 0 // Private note for admin only 1059 ); 1060 } 1061 } 1062 } 1063 } 1064 } 1065 elseif( $cod24_info['shipping_type'] == 'tipax' ) 1066 { 1067 // Check if the weight post meta is empty 1068 if ( empty( $cod24_last_status ) ) 1069 { 1070 // Add an order note for admin 1071 $order->add_order_note( 1072 esc_attr__( 'You should select the "Suspend Order" status first.', 'cod24-shipping' ), 1073 0 // Private note for admin only 1074 ); 1075 } 1076 else 1077 { 1078 $result = COD24_Tipax_API::ready_to_send_order( array( array( 'serial' => absint( $cod24_info['serial'] ), 'idOrderShop' => strval( $order_id ) ) ) ); 1079 792 1080 if( $result[0]['isSuccess'] && $result[0]['code'] == 0 ) 793 1081 { … … 797 1085 1 // Public note 798 1086 ); 1087 1088 $cod24_info['barcode'] = $result[0]['barcode']; 1089 $order->update_meta_data( '_cod24_info', $cod24_info ); 799 1090 800 1091 $order->update_status( 'cod24-ready-send' ); … … 822 1113 } 823 1114 } 824 }825 }1115 } 1116 } 826 1117 } 827 1118 elseif ( $cod24_new_status == 'cod24-cancel' && $cod24_last_status != 'cod24-cancel' ) // If the new status is 'cod24-cancel' 828 1119 { 829 if( empty( $cod24_ serial) )1120 if( empty( $cod24_info['serial'] ) ) 830 1121 { 831 1122 // Add an order note for admin … … 837 1128 else 838 1129 { 839 $result = COD24_API::cancel_order( array( 'serial' => $cod24_serial, 'idOrderShop' => (string) $order_id ) ); 1130 if( $cod24_info['shipping_type'] == 'tipax' ) 1131 $result = COD24_Tipax_API::cancel_order( array( array( 'serial' => $cod24_info['serial'], 'idOrderShop' => strval( $order_id ) ) ) ); 1132 else 1133 $result = COD24_API::cancel_order( array( array( 'serial' => $cod24_info['serial'], 'idOrderShop' => strval( $order_id ) ) ) ); 840 1134 841 1135 if( $result[0]['isSuccess'] && $result[0]['code'] == 0 ) … … 855 1149 else 856 1150 { 857 if( !empty( $result[0]['code'] ) && !empty( $result[0]['message'] ) )1151 if( !empty( $result[0]['code'] ) && !empty( $result[0]['message'] ) ) 858 1152 { 859 1153 // Add an order note for admin 860 1154 $order->add_order_note( 861 1155 sprintf( __( 'There is a problem when cancelling the order in the COD24 panel. Error: %1$s - %2$s', 'cod24-shipping' ), $result[0]['code'] , $result[0]['message'] ), 1156 0 // Private note for admin only 1157 ); 1158 } 1159 elseif( !empty( $result['code'] ) && !empty( $result['message'] ) ) 1160 { 1161 // Add an order note for admin 1162 $order->add_order_note( 1163 sprintf( __( 'There is a problem when cancelling the order in the COD24 panel. Error: %1$s - %2$s', 'cod24-shipping' ), $result['code'] , $result['message'] ), 862 1164 0 // Private note for admin only 863 1165 ); … … 873 1175 } 874 1176 } 875 876 $result = array( 'status' => true, 'url' => add_query_arg( array( 'post' => $order_id , 'action' => 'edit' ), admin_url( 'post.php' ) ) ); 1177 1178 if( !empty( $error_message ) ) 1179 $result = array( 'status' => false, 'msg' => $error_message, 'url' => add_query_arg( array( 'post' => $order_id , 'action' => 'edit' ), admin_url( 'post.php' ) ) ); 1180 else 1181 $result = array( 'status' => true, 'url' => add_query_arg( array( 'post' => $order_id , 'action' => 'edit' ), admin_url( 'post.php' ) ) ); 877 1182 } 878 1183 else … … 910 1215 if( !empty( $order_info->get_id() ) ) 911 1216 { 912 $cod24_ serial = $order_info->get_meta('_cod24_serial', true);913 if( !empty( $cod24_ serial) )1217 $cod24_info = $order_info->get_meta('_cod24_info', true); 1218 if( !empty( $cod24_info['serial'] ) ) 914 1219 { 915 $data[] = [ 'serial' => (int) $cod24_ serial];1220 $data[] = [ 'serial' => (int) $cod24_info['serial'] ]; 916 1221 $factor_preview_result = COD24_API::factor_preview( $data ); 917 1222 if( !empty( $factor_preview_result['url'] ) ) … … 956 1261 if( !empty( $order_info->get_id() ) ) 957 1262 { 958 $cod24_ serial = $order_info->get_meta('_cod24_serial', true );959 if( !empty( $cod24_ serial) )1263 $cod24_info = $order_info->get_meta('_cod24_info', true ); 1264 if( !empty( $cod24_info['serial'] ) ) 960 1265 { 961 $data[] = [ 'serial' => (int) $cod24_ serial];1266 $data[] = [ 'serial' => (int) $cod24_info['serial'] ]; 962 1267 $barcode_preview_result = COD24_API::barcode_preview( $data ); 963 1268 if( !empty( $barcode_preview_result['url'] ) ) … … 1021 1326 { 1022 1327 case 'cod24' : 1023 // Get cod24 serial 1024 $cod24_serial = $order->get_meta('_cod24_serial', true); 1025 /* translators: %s is the post serial */ 1328 // Get cod24 info 1329 $cod24_info = $order->get_meta('_cod24_info', true); 1330 1331 /* cod24 shipping type */ 1332 $shipping_type_output = sprintf( 1333 __("Shipping Type: <strong>%s</strong>", 'cod24-shipping'), 1334 !empty($cod24_info['shipping_type']) ? esc_attr( ucwords( $cod24_info['shipping_type'] ) ) : '-' 1335 ); 1336 1337 /* cod24 serial */ 1026 1338 $serial_output = sprintf( 1027 __(" Serial: <strong>%s</strong>", 'cod24-shipping'),1028 !empty($cod24_ serial) ? esc_attr($cod24_serial) : '-'1339 __("<br />Serial: <strong>%s</strong>", 'cod24-shipping'), 1340 !empty($cod24_info['serial']) ? esc_attr($cod24_info['serial']) : '-' 1029 1341 ); 1030 1342 1031 // Get cod24 barcode 1032 $cod24_barcode = $order->get_meta('_cod24_barcode', true); 1033 /* translators: %s is the post barcode */ 1343 /* cod24 barcode */ 1034 1344 $barcode_output = sprintf( 1035 __("<br /> PostBarcode: <strong>%s</strong>", 'cod24-shipping'),1036 !empty($cod24_ barcode) ? esc_attr($cod24_barcode) : '-'1345 __("<br />Barcode: <strong>%s</strong>", 'cod24-shipping'), 1346 !empty($cod24_info['barcode']) ? esc_attr($cod24_info['barcode']) : '-' 1037 1347 ); 1038 1348 1039 echo $s erial_output . $barcode_output;1349 echo $shipping_type_output. $serial_output . $barcode_output; 1040 1350 break; 1041 1351 } … … 1133 1443 { 1134 1444 $result = []; 1135 $valid_process = 1; 1445 $valid_weight = 1; 1446 $valid_carton_size = 1; 1447 $user_total_weight = 0; 1136 1448 if( isset( $_POST['cod24_form_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash ( $_POST['cod24_form_nonce'] ) ) , 'cod24_form_nonce') ) 1137 1449 { … … 1145 1457 // check total weight and carton size is valid or no 1146 1458 $process_only_orders = 0; 1147 1148 // check weight type1149 if( isset( $_POST['weight_type'] ) && !empty( $_POST['weight_type'] ) )1150 {1151 $weight_type = sanitize_text_field( $_POST['weight_type'] );1152 if( $weight_type == 'total_weight' )1153 {1154 $process_only_orders = 1;1155 }1156 elseif( $weight_type == 'custom_weight' )1157 {1158 // check total weight1159 if( isset( $_POST['custom_total_weight'] ) && !empty( $_POST['custom_total_weight'] ) )1160 {1161 $user_total_weight = absint( $_POST['custom_total_weight'] );1162 if( !empty( $user_total_weight ) && absint( $user_total_weight ) > 0 )1163 {1164 // check carton size1165 if( isset( $_POST['carton_size'] ) && !empty( $_POST['carton_size'] ) && $_POST['carton_size'] != 'none' )1166 {1167 $carton_sizes = COD24_API::get_carton_sizes();1168 $user_carton_size = sanitize_text_field( $_POST['carton_size'] );1169 if( in_array( $user_carton_size, array_keys( $carton_sizes ) ) )1170 {1171 // do nothing1172 $result = array( 'status' => true );1173 $valid_process = 1;1174 }1175 else1176 {1177 $result = array( 'status' => false, 'msg' => __('The carton size value is invalid', 'cod24-shipping') );1178 $valid_process = 0;1179 }1180 }1181 else1182 {1183 $result = array( 'status' => false, 'msg' => __('Please fill in the carton size field', 'cod24-shipping') );1184 $valid_process = 0;1185 }1186 }1187 else1188 {1189 $result = array( 'status' => false, 'msg' => __('The weight value is invalid', 'cod24-shipping') );1190 $valid_process = 0;1191 }1192 }1193 else1194 {1195 $result = array( 'status' => false, 'msg' => __('Please fill in the weight field', 'cod24-shipping') );1196 $valid_process = 0;1197 }1198 }1199 else1200 {1201 $result = array( 'status' => false, 'msg' => __('The weight type is invalid', 'cod24-shipping') );1202 $valid_process = 0;1203 }1204 }1205 else1206 {1207 $result = array( 'status' => false, 'msg' => __('Please select the weight type', 'cod24-shipping') );1208 $valid_process = 0;1209 }1210 1211 1459 } 1212 1460 else … … 1214 1462 $process_only_orders = 1; 1215 1463 } 1216 1217 if( $valid_process ) 1464 1465 // check weight type 1466 if( ! $process_only_orders ) 1218 1467 { 1468 if( isset( $_POST['weight_type'] ) && !empty( $_POST['weight_type'] ) ) 1469 { 1470 $weight_type = sanitize_text_field( $_POST['weight_type'] ); 1471 if( in_array( $weight_type , array( 'total_weight', 'custom_weight' ) ) ) 1472 { 1473 if( $weight_type == 'custom_weight' ) 1474 { 1475 if( isset( $_POST['custom_total_weight'] ) && !empty( $_POST['custom_total_weight'] ) ) 1476 { 1477 $user_total_weight = absint( $_POST['custom_total_weight'] ); 1478 if( !empty( $user_total_weight ) && absint( $user_total_weight ) > 0 ) 1479 { 1480 $valid_weight = 1; 1481 } 1482 else 1483 { 1484 $result = array( 'status' => false, 'msg' => __('The weight value is invalid', 'cod24-shipping') ); 1485 $valid_weight = 0; 1486 } 1487 } 1488 else 1489 { 1490 $result = array( 'status' => false, 'msg' => __('Please fill in the weight field', 'cod24-shipping') ); 1491 $valid_weight = 0; 1492 } 1493 } 1494 else 1495 { 1496 $valid_weight = 1; 1497 } 1498 } 1499 else 1500 { 1501 $result = array( 'status' => false, 'msg' => __('The weight type is invalid', 'cod24-shipping') ); 1502 $valid_weight = 0; 1503 } 1504 } 1505 else 1506 { 1507 $result = array( 'status' => false, 'msg' => __('Please select the weight type', 'cod24-shipping') ); 1508 $valid_weight = 0; 1509 } 1510 1511 if( ! $process_only_orders && $valid_weight ) 1512 { 1513 // check carton size 1514 if( isset( $_POST['carton_size'] ) && !empty( $_POST['carton_size'] ) && $_POST['carton_size'] != 'none' ) 1515 { 1516 $carton_sizes = COD24_Tipax_API::get_carton_sizes(); 1517 $user_key_carton_size = sanitize_text_field( $_POST['carton_size'] ); 1518 if( in_array( $user_key_carton_size, array_keys( $carton_sizes ) ) ) 1519 { 1520 // do nothing 1521 $user_carton_size = array_search( $user_key_carton_size, array_keys( $carton_sizes ) ) + 1; 1522 $result = array( 'status' => true ); 1523 $valid_carton_size = 1; 1524 } 1525 else 1526 { 1527 $result = array( 'status' => false, 'msg' => __('The carton size value is invalid', 'cod24-shipping') ); 1528 $valid_carton_size = 0; 1529 } 1530 } 1531 else 1532 { 1533 $result = array( 'status' => false, 'msg' => __('Please fill in the carton size field', 'cod24-shipping') ); 1534 $valid_carton_size = 0; 1535 } 1536 } 1537 } 1538 1539 1540 if( $valid_weight && $valid_carton_size ) 1541 { 1219 1542 // process orders and check order ids 1220 1543 if( isset( $_POST['order_ids'] ) && !empty( $_POST['order_ids'] ) ) … … 1222 1545 $error_orders = []; 1223 1546 $verified_orders = 0; 1224 $sanitized_data = []; 1547 $post_sanitized_data = []; 1548 $tipax_sanitized_data = []; 1225 1549 $user_order_ids = array_map('absint', $_POST['order_ids'] ); 1226 1550 foreach( $user_order_ids as $order_id ) 1227 1551 { 1228 1552 $order = wc_get_order( $order_id ); 1229 1230 // update custom total weight & carton size 1231 if( $process_only_orders == 0 ) // for cod24 add status 1232 { 1233 $order->update_meta_data( '_custom_total_weight', $user_total_weight ); 1234 $order->update_meta_data( '_cod24_carton_size', $user_carton_size ); 1235 $order->save(); 1236 } 1237 1553 1238 1554 if( $order ) 1239 1555 { 1240 $cod24_serial = $order->get_meta( '_cod24_serial', true); 1241 $cod24_barcode = $order->get_meta( '_cod24_barcode', true); 1242 $cod24_last_status = $order->get_meta('_cod24_last_status', true ); 1556 $cod24_last_status = $order->get_meta('_cod24_last_status', true ); 1557 $cod24_info = $order->get_meta( '_cod24_info', true); 1558 1559 // update custom total weight & carton size & dimension 1560 if( $process_only_orders == 0 ) // for cod24 add status 1561 { 1562 // check total weight 1563 if( $weight_type == 'custom_weight' ) 1564 { 1565 $cod24_info['total_weight'] = floatval( $_POST['custom_total_weight'] ); 1566 } 1567 else 1568 { 1569 $cod24_info['total_weight'] = $cod24_info['total_weight']; 1570 } 1571 1572 if( $cod24_info['shipping_type'] == 'post' ) 1573 { 1574 if( ! isset( $cod24_info['non_standard_package'] ) ) 1575 $cod24_info['non_standard_package'] = 'no'; 1576 1577 $cod24_info['carton_size'] = $user_carton_size; 1578 } 1579 elseif( $cod24_info['shipping_type'] == 'tipax' ) 1580 { 1581 if( !empty( $_POST['dimension_length'] ) && !empty( $_POST['dimension_width'] ) && !empty( $_POST['dimension_height'] ) ) 1582 { 1583 $cod24_info['total_dimension'] = array( 1584 'length' => floatval( sanitize_text_field( $_POST['dimension_length'] ) ), 1585 'width' => floatval( sanitize_text_field( $_POST['dimension_width'] ) ), 1586 'height' => floatval( sanitize_text_field( $_POST['dimension_height'] ) ) 1587 ); 1588 } 1589 1590 if( ! isset( $cod24_info['non_standard_package'] ) ) 1591 $cod24_info['non_standard_package'] = 'no'; 1592 1593 if( ! isset( $cod24_info['pack_type'] ) ) 1594 $cod24_info['pack_type'] = 20; 1595 1596 if( ! isset( $cod24_info['package_content'] ) ) 1597 $cod24_info['package_content'] = 9; 1598 1599 if( ! isset( $cod24_info['pickup_type'] ) ) 1600 $cod24_info['pickup_type'] = 20; 1601 1602 if( ! isset( $cod24_info['distribution_type'] ) ) 1603 $cod24_info['distribution_type'] = 20; 1604 } 1605 1606 $order->update_meta_data( '_cod24_info', $cod24_info ); 1607 $order->save(); 1608 } 1609 1610 $cod24_info = $order->get_meta( '_cod24_info', true); 1243 1611 1244 1612 if( $cod24_status == 'mark_cod24_add') 1245 1613 { 1246 if( empty( $cod24_ serial) )1614 if( empty( $cod24_info['serial'] ) ) 1247 1615 { 1248 1616 // send to api 1249 $sanitized_data[] = $order_id; 1250 1617 if( $cod24_info['shipping_type'] == 'post' ) 1618 { 1619 $post_sanitized_data[] = $order_id; 1620 } 1621 elseif( $cod24_info['shipping_type'] == 'tipax' ) 1622 { 1623 $tipax_sanitized_data[] = $order_id; 1624 } 1251 1625 } 1252 1626 else … … 1274 1648 else 1275 1649 { 1276 if( empty( $cod24_ barcode ) && !empty( $cod24_serial) )1650 if( empty( $cod24_info['barcode'] ) && !empty( $cod24_info['serial'] ) ) 1277 1651 { 1278 // send to api 1279 $sanitized_data[] = array( 'idOrderShop' => (string) $order_id , 'serial' => $cod24_serial ); 1652 if( $cod24_info['shipping_type'] == 'post') 1653 { 1654 // send to api 1655 $post_sanitized_data[] = array( 'idOrderShop' => strval( $order_id ), 'serial' => $cod24_info['serial'] ); 1656 } 1657 elseif( $cod24_info['shipping_type'] == 'tipax') 1658 { 1659 $order->add_order_note( 1660 sprintf( __( 'This status is only available for Post shipping, not Tipax shipping.', 'cod24-shipping' ) ), 1661 0 // Private note for admin only 1662 ); 1663 1664 $error_orders[] = $order_id; 1665 } 1280 1666 } 1281 1667 else … … 1292 1678 elseif( $cod24_status == 'mark_cod24_ready_send') 1293 1679 { 1294 // Check if the weight post meta is empty 1295 if ( empty( $cod24_last_status ) || ( !empty( $cod24_last_status ) && $cod24_last_status != 'cod24-suspend' ) ) 1296 { 1297 // Add an order note for admin 1298 $order->add_order_note( 1299 esc_attr__( 'You should select the "Suspend Order" status first.', 'cod24-shipping' ), 1300 0 // Private note for admin only 1301 ); 1302 1303 $error_orders[] = $order_id; 1304 } 1305 else 1306 { 1307 if( empty( $cod24_barcode ) ) 1308 { 1309 // Add an order note for admin 1310 $order->add_order_note( 1311 esc_attr__( 'No Post Barcode registered for this order.', 'cod24-shipping' ), 1312 0 // Private note for admin only 1313 ); 1314 1315 $error_orders[] = $order_id; 1316 } 1317 else 1318 { 1319 // send to api 1320 $sanitized_data[] = array( 'idOrderShop' => (string) $order_id , 'serial' => absint( $cod24_serial ) ); 1321 } 1322 } 1680 // check if shipping type is post or tipax 1681 if( $cod24_info['shipping_type'] == 'post') 1682 { 1683 // Check if the weight post meta is empty 1684 if ( empty( $cod24_last_status ) || ( !empty( $cod24_last_status ) && $cod24_last_status != 'cod24-suspend' ) ) 1685 { 1686 // Add an order note for admin 1687 $order->add_order_note( 1688 esc_attr__( 'You should select the "Suspend Order" status first.', 'cod24-shipping' ), 1689 0 // Private note for admin only 1690 ); 1691 1692 $error_orders[] = $order_id; 1693 } 1694 else 1695 { 1696 if( empty( $cod24_info['barcode'] ) ) 1697 { 1698 // Add an order note for admin 1699 $order->add_order_note( 1700 esc_attr__( 'No Barcode registered for this order.', 'cod24-shipping' ), 1701 0 // Private note for admin only 1702 ); 1703 1704 $error_orders[] = $order_id; 1705 } 1706 else 1707 { 1708 // send to api 1709 $post_sanitized_data[] = array( 'idOrderShop' => strval( $order_id ), 'serial' => absint( $cod24_info['serial'] ) ); 1710 } 1711 } 1712 } 1713 elseif( $cod24_info['shipping_type'] == 'tipax') 1714 { 1715 // Check if the weight post meta is empty 1716 if ( empty( $cod24_last_status ) || ( !empty( $cod24_last_status ) && $cod24_last_status != 'cod24-add' ) ) 1717 { 1718 // Add an order note for admin 1719 $order->add_order_note( 1720 esc_attr__( 'You should select the "Add Order" status first.', 'cod24-shipping' ), 1721 0 // Private note for admin only 1722 ); 1723 1724 $error_orders[] = $order_id; 1725 } 1726 else 1727 { 1728 // send to api 1729 $tipax_sanitized_data[] = array( 'idOrderShop' => strval( $order_id ), 'serial' => absint( $cod24_info['serial'] ) ); 1730 } 1731 } 1323 1732 } 1324 1733 elseif( $cod24_status == 'mark_cod24_cancel') 1325 1734 { 1326 if( empty( $cod24_ serial) )1735 if( empty( $cod24_info['serial'] ) ) 1327 1736 { 1328 1737 // Add an order note for admin … … 1336 1745 else 1337 1746 { 1338 $sanitized_data[] = array( 'idOrderShop' => (string) $order_id, 'serial' => absint( $cod24_serial ) ); 1747 if( $cod24_info['shipping_type'] == 'post' ) 1748 $post_sanitized_data[] = array( 'idOrderShop' => strval( $order_id ), 'serial' => absint( $cod24_info['serial'] ) ); 1749 elseif( $cod24_info['shipping_type'] == 'tipax' ) 1750 $tipax_sanitized_data[] = array( 'idOrderShop' => strval( $order_id ), 'serial' => absint( $cod24_info['serial'] ) ); 1339 1751 } 1340 1752 } 1341 1753 elseif( $cod24_status == 'mark_cod24_print') 1342 1754 { 1343 if( !empty( $cod24_ serial ) && !empty( $cod24_barcode) )1755 if( !empty( $cod24_info['serial'] ) && !empty( $cod24_info['barcode'] ) ) 1344 1756 { 1345 $sanitized_data[] = array( 'serial' => $cod24_ serial);1757 $sanitized_data[] = array( 'serial' => $cod24_info['serial'] ); 1346 1758 } 1347 1759 else … … 1363 1775 1364 1776 // sanitized data 1365 if( !empty( $ sanitized_data ) )1777 if( !empty( $post_sanitized_data ) || !empty( $tipax_sanitized_data ) ) 1366 1778 { 1367 1779 if( $cod24_status == 'mark_cod24_add' ) 1368 1780 { 1369 $result = COD24_API::add_order_batch( $sanitized_data ); 1781 $post_result = []; 1782 $tipax_result = []; 1370 1783 1784 if( !empty( $post_sanitized_data ) ) 1785 $post_result = COD24_API::add_order_batch( $post_sanitized_data ); 1786 1787 if( !empty( $tipax_sanitized_data ) ) 1788 $tipax_result = COD24_Tipax_API::add_order_batch( $tipax_sanitized_data ); 1789 1790 $result = array_merge($post_result, $tipax_result); 1791 1371 1792 if( !empty( $result ) ) 1372 1793 { … … 1374 1795 { 1375 1796 $order = wc_get_order( $item['idOrderShop'] ); 1797 $cod24_info = $order->get_meta( '_cod24_info', true); 1376 1798 1377 1799 if( $order ) … … 1380 1802 { 1381 1803 // update serial 1382 $ order->update_meta_data( '_cod24_serial', $item['serial'] );1804 $cod24_info['serial'] = $item['serial']; 1383 1805 1384 1806 // Add an order note for user … … 1392 1814 // update cod24 last status 1393 1815 $order->update_meta_data( '_cod24_last_status', 'cod24-add' ); 1816 1817 $order->update_meta_data( '_cod24_info', $cod24_info ); 1394 1818 1395 1819 $verified_orders++; … … 1409 1833 // Add an order note for admin 1410 1834 $order->add_order_note( 1411 sprintf( __( 'There is a problem when adding the order to the COD24 panel. Error: <br />%s', 'cod24-shipping' ), $errors ),1835 sprintf( __( 'There is a problem when adding the order to the COD24 panel. Error: %s', 'cod24-shipping' ), $errors ), 1412 1836 0 // Private note for admin only 1413 1837 ); … … 1449 1873 elseif( $cod24_status == 'mark_cod24_suspend') 1450 1874 { 1451 $result = COD24_API::suspend_order( $sanitized_data ); 1875 $post_result = []; 1876 $tipax_result = []; 1877 if( !empty( $post_sanitized_data ) ) 1878 $post_result = COD24_API::suspend_order( $post_sanitized_data ); 1879 1880 $result = array_merge($post_result, $tipax_result); 1452 1881 1453 1882 if( !empty( $result ) ) … … 1455 1884 foreach($result as $item) 1456 1885 { 1457 $order = wc_get_order( $item['idOrderShop'] ); 1886 $order = wc_get_order( absint( $item['idOrderShop'] ) ); 1887 $cod24_info = $order->get_meta( '_cod24_info', true); 1458 1888 1459 1889 if( $order ) … … 1462 1892 { 1463 1893 // update barcode 1464 $ order->update_meta_data( '_cod24_barcode', $item['barcode'] );1894 $cod24_info['barcode'] = $item['barcode']; 1465 1895 1466 1896 // Add an order note for user 1467 1897 $order->add_order_note( 1468 sprintf( esc_attr__('The order successfully suspended in the COD24 panel. PostBarcode: %s', 'cod24-shipping' ), $item['barcode'] ),1898 sprintf( esc_attr__('The order successfully suspended in the COD24 panel. Barcode: %s', 'cod24-shipping' ), $item['barcode'] ), 1469 1899 1 // Public note 1470 1900 ); … … 1474 1904 // update cod24 last status 1475 1905 $order->update_meta_data( '_cod24_last_status', 'cod24-suspend' ); 1906 1907 $order->update_meta_data( '_cod24_info', $cod24_info ); 1476 1908 1477 1909 $verified_orders++; … … 1507 1939 elseif( $cod24_status == 'mark_cod24_ready_send') 1508 1940 { 1509 $result = COD24_API::ready_to_send_order( $sanitized_data ); 1941 $post_result = []; 1942 $tipax_result = []; 1943 1944 if( !empty( $post_sanitized_data ) ) 1945 $post_result = COD24_API::ready_to_send_order( $post_sanitized_data ); 1946 1947 if( !empty( $tipax_sanitized_data ) ) 1948 $tipax_result = COD24_Tipax_API::ready_to_send_order( $tipax_sanitized_data ); 1949 1950 $result = array_merge($post_result, $tipax_result); 1510 1951 1511 1952 if( !empty( $result ) ) … … 1514 1955 { 1515 1956 $order = wc_get_order( $item['idOrderShop'] ); 1957 $cod24_info = $order->get_meta( '_cod24_info', true); 1516 1958 1517 1959 if( $order ) … … 1529 1971 // update cod24 last status 1530 1972 $order->update_meta_data( '_cod24_last_status', 'cod24-ready-send' ); 1973 1974 if( $cod24_info['shipping_type'] == 'tipax' ) 1975 { 1976 $cod24_info['barcode'] = $item['barcode']; 1977 $order->update_meta_data( '_cod24_info', $cod24_info ); 1978 } 1531 1979 1532 1980 $verified_orders++; … … 1562 2010 elseif( $cod24_status == 'mark_cod24_cancel') 1563 2011 { 1564 $result = COD24_API::cancel_order( $sanitized_data ); 2012 $post_result = []; 2013 $tipax_result = []; 2014 if( !empty( $post_sanitized_data ) ) 2015 $post_result = COD24_API::cancel_order( $post_sanitized_data ); 2016 2017 if( !empty( $tipax_sanitized_data ) ) 2018 $tipax_result = COD24_Tipax_API::cancel_order( $tipax_sanitized_data ); 2019 2020 $result = array_merge($post_result, $tipax_result); 1565 2021 1566 2022 if( !empty( $result ) ) … … 1663 2119 { 1664 2120 $message = sprintf( 1665 _n('%1$d order out of %2$d was successfully added to the COD24 panel.', '%1$d orders out of %2$d were successfully added to the COD24 panel.', $ count, 'cod24-shipping'),2121 _n('%1$d order out of %2$d was successfully added to the COD24 panel.', '%1$d orders out of %2$d were successfully added to the COD24 panel.', $verified_orders, 'cod24-shipping'), 1666 2122 $verified_orders, 1667 2123 count( $user_order_ids ) … … 1671 2127 { 1672 2128 $message = sprintf( 1673 _n('%1$d order out of %2$d was successfully suspended in the COD24 panel.', '%1$d orders out of %2$d were successfully suspended in the COD24 panel.', $ count, 'cod24-shipping'),2129 _n('%1$d order out of %2$d was successfully suspended in the COD24 panel.', '%1$d orders out of %2$d were successfully suspended in the COD24 panel.', $verified_orders, 'cod24-shipping'), 1674 2130 $verified_orders, 1675 2131 count( $user_order_ids ) … … 1679 2135 { 1680 2136 $message = sprintf( 1681 _n('%1$d order out of %2$d changed to "Ready To Send" status in the COD24 panel successfully.', '%1$d orders out of %2$d changed to "Ready To Send" status in the COD24 panel successfully.', $ count, 'cod24-shipping'),2137 _n('%1$d order out of %2$d changed to "Ready To Send" status in the COD24 panel successfully.', '%1$d orders out of %2$d changed to "Ready To Send" status in the COD24 panel successfully.', $verified_orders, 'cod24-shipping'), 1682 2138 $verified_orders, 1683 2139 count( $user_order_ids ) … … 1687 2143 { 1688 2144 $message = sprintf( 1689 _n('%1$d order out of %2$d was successfully cancelled in the COD24 panel.', '%1$d orders out of %2$d were successfully cancelled in the COD24 panel.', $ count, 'cod24-shipping'),2145 _n('%1$d order out of %2$d was successfully cancelled in the COD24 panel.', '%1$d orders out of %2$d were successfully cancelled in the COD24 panel.', $verified_orders, 'cod24-shipping'), 1690 2146 $verified_orders, 1691 2147 count( $user_order_ids ) -
cod24-shipping/trunk/readme.txt
r3248145 r3254068 1 1 === COD24 Shipping For Woocommerce === 2 2 Contributors: cod24, vadatiertebat 3 Tags: cod24, delivery, tipax, woocommerce shipping, shipping method3 Tags: cod24, iran shipping, tipax, woocommerce shipping, shipping method 4 4 Requires at least: 5.0 5 5 Tested up to: 6.7 6 Stable tag: 3.4.66 Stable tag: 4.0 7 7 License: GPL-2.0+ 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 20 20 - Ability to add Iran Post's priority shipping in WooCommerce 21 21 - Ability to activate Iran Post's special shipping in WooCommerce 22 - Ability to activate Tipax shipping (coming soon)22 - Ability to activate Tipax shipping 23 23 - Ability to activate Chapar & Alopeyk (coming soon) 24 24 … … 41 41 42 42 You first need to purchase the COD24 postal panel. Then, you need to obtain the web service key and enter it in the plugin settings section of the WooCommerce configuration. Once this is done, the plugin will be connected to the postal panel. 43 44 == Changelog == 45 46 = 4.0 = 47 * Added Tipax Shipping 48 * New structure for saving data 49 * Fixed free shipping 50 * Bugs fixes and improvements 51 52 = 3.4.6 = 53 * Compatible with the latest Woocommerce 54 * Cached COD24 wallet amount 55 * Bugs fixes and improvements 56 57 = 3.4.5 = 58 * Bugs fixes and improvements 59 60 = 3.4.4 = 61 * Bugs fixes and improvements 62 63 = 3.4.3 = 64 * Compatible with the latest WordPress & Woocommerce version 65 * Bugs fixes and improvements 66 67 = 3.4.2 = 68 * Bugs fixes and improvements 69 70 = 3.4.1 = 71 * Bugs fixes and improvements 72 73 = 3.4 = 74 * Launch first version in WordPress Repository 75 * Includes Pishtaz & Special Post Shipping
Note: See TracChangeset
for help on using the changeset viewer.