Changeset 3404922
- Timestamp:
- 11/28/2025 09:01:53 AM (6 weeks ago)
- Location:
- a2z-canada-post-automated-shipping/trunk
- Files:
-
- 4 edited
-
controllors/hit_canadapost_auto_init.php (modified) (4 diffs)
-
controllors/views/hit_canadapost_auto_settings_view.php (modified) (6 diffs)
-
hit_canadapost_auto_basic.php (modified) (6 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
a2z-canada-post-automated-shipping/trunk/controllors/hit_canadapost_auto_init.php
r3347108 r3404922 297 297 298 298 $des_coun = $pack_aft_hook['destination']['country']; 299 $from_coun = $general_settings['hit_cp_auto_country']; 299 300 $orderCurrency = $value[$des_coun]['currency']; 301 $zonos_rates_key = 'credential_live_d12bd9d7-de0d-4f9b-aeb8-254141252144'; 300 302 301 303 if(isset($general_settings['hit_cp_auto_rates']) && $general_settings['hit_cp_auto_rates'] == 'yes' && isset($pack_aft_hook['destination']['country']) && !empty($pack_aft_hook['destination']['country'])) … … 392 394 393 395 // Non-Delivery Handling 394 $ndh = '';395 if(isset($general_settings['hit_cp_auto_ndh']) && $general_settings['hit_cp_auto_ndh'] !== 'N') {396 $ndh = $general_settings['hit_cp_auto_ndh'];397 }398 if($des_coun == 'US') {399 $ndh = 'RASE';400 }401 if(!empty($ndh)) {402 $options_xml .= '<option><option-code>'.$ndh.'</option-code></option>';403 }396 // $ndh = ''; 397 // if(isset($general_settings['hit_cp_auto_ndh']) && $general_settings['hit_cp_auto_ndh'] !== 'N') { 398 // $ndh = $general_settings['hit_cp_auto_ndh']; 399 // } 400 // if($des_coun == 'US') { 401 // $ndh = 'RASE'; 402 // } 403 // if(!empty($ndh)) { 404 // $options_xml .= '<option><option-code>'.$ndh.'</option-code></option>'; 405 // } 404 406 405 407 // Insurance … … 559 561 if($rate_cost > 0) 560 562 { 561 562 563 $rate_name = $_carriers[$rate_code]; 563 564 $name = isset($carriers_name_available[$rate_code]) && !empty($carriers_name_available[$rate_code]) ? $carriers_name_available[$rate_code] : $rate_name; 564 565 565 566 // Zonos Landed Cost Integration 567 if (isset($zonos_rates_key) && !empty($zonos_rates_key) && isset($general_settings['hit_cp_auto_rates_with_duties']) && $general_settings['hit_cp_auto_rates_with_duties'] == 'yes' && $des_coun == 'US') { 568 $zonos_duties = $this->get_zonos_landed_cost($pack_aft_hook, $zonos_rates_key, $des_coun, $rate_cst, $from_coun); 569 if ($zonos_duties > 0) { 570 $rate_cst += $zonos_duties; 571 $name .= ' (Custom Duties Included: ' . round($zonos_duties) . ')'; 572 } 573 } 574 566 575 $rate = array( 567 576 'id' => 'hits'.$rate_code, … … 978 987 } 979 988 980 981 } 989 /** 990 * Calculate Landed Cost via Zonos API 991 */ 992 private function get_zonos_landed_cost($products, $zonos_key, $destination_country, $shipping_cost, $from_country) { 993 $url = 'https://api.zonos.com/v1/landed_cost'; 994 $zonos_key = trim($zonos_key); 995 if (empty($zonos_key)) { 996 return 0; 997 } 998 $items = array(); 999 1000 // Check if contents exist and is an array 1001 if (isset($products['contents']) && is_array($products['contents'])) { 1002 foreach($products['contents'] as $item) { 1003 if (isset($item['data']) && is_object($item['data'])) { 1004 $product = $item['data']; 1005 1006 // Get product data safely 1007 $product_id = method_exists($product, 'get_id') ? $product->get_id() : 0; 1008 $price = method_exists($product, 'get_price') ? $product->get_price() : 0; 1009 $name = method_exists($product, 'get_name') ? $product->get_name() : 'Item'; 1010 $hs_code = method_exists($product, 'get_meta') ? $product->get_meta('hits_cp_hs_code') : ''; 1011 $quantity = isset($item['quantity']) ? $item['quantity'] : 1; 1012 $items[] = array( 1013 'id' => (string) $product_id, 1014 'amount' => $price, 1015 'description_retail' => $name, 1016 'quantity' => $quantity, 1017 // 'country_of_origin' => $from_country, 1018 'hs_code' => $hs_code, 1019 ); 1020 } 1021 } 1022 } 1023 if (empty($items)) { 1024 return 0; 1025 } 1026 $ship_to = array( 1027 'country' => $destination_country, 1028 ); 1029 if (isset($products['destination'])) { 1030 if (!empty($products['destination']['state'])) { 1031 $ship_to['state'] = $products['destination']['state']; 1032 } 1033 if (!empty($products['destination']['city'])) { 1034 $ship_to['city'] = $products['destination']['city']; 1035 } 1036 if (!empty($products['destination']['postcode'])) { 1037 $ship_to['zip'] = $products['destination']['postcode']; 1038 } 1039 } 1040 $data = array( 1041 'currency' => 'CAD', 1042 'items' => $items, 1043 'ship_from_country' => $from_country, 1044 'ship_to' => $ship_to, 1045 'shipping' => array( 1046 'amount' => $shipping_cost, 1047 ), 1048 ); 1049 $headers = array( 1050 'Content-Type: application/json', 1051 'serviceToken: ' . $zonos_key, 1052 'zonos-version: 2019-11-21' 1053 ); 1054 $curl = curl_init($url); 1055 curl_setopt($curl, CURLOPT_POST, true); 1056 curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); 1057 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 1058 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); 1059 $response = curl_exec($curl); 1060 curl_close($curl); 1061 if ($response) { 1062 $json = json_decode($response, true); 1063 if (!empty($json['amount_subtotal'])) { 1064 $duties = (float) ($json['amount_subtotal']['duties'] ?? 0); 1065 $fees = (float) ($json['amount_subtotal']['fees'] ?? 0); 1066 $taxes = (float) ($json['amount_subtotal']['taxes'] ?? 0); 1067 // Canada Post clearance fee 1068 // Only apply if shipping is Canada Post 1069 $canada_post_processing = 1.99 + ($duties * 0.10); 1070 return $duties + $fees + $taxes + $canada_post_processing; 1071 } 1072 } 1073 return 0; 1074 } 982 1075 } 1076 } -
a2z-canada-post-automated-shipping/trunk/controllors/views/hit_canadapost_auto_settings_view.php
r3347096 r3404922 572 572 $general_settings['hit_cp_auto_site_pwd'] = sanitize_text_field(isset($_POST['hit_cp_auto_site_pwd']) ? $_POST['hit_cp_auto_site_pwd'] : ''); 573 573 $general_settings['hit_cp_auto_acc_no'] = sanitize_text_field(isset($_POST['hit_cp_auto_acc_no']) ? $_POST['hit_cp_auto_acc_no'] : ''); 574 $general_settings['hit_cp_auto_zonos_acc_no'] = sanitize_text_field(isset($_POST['hit_cp_auto_zonos_acc_no']) ? $_POST['hit_cp_auto_zonos_acc_no'] : ''); 574 575 $general_settings['hit_cp_auto_access_key'] = sanitize_text_field(isset($_POST['hit_cp_auto_access_key']) ? $_POST['hit_cp_auto_access_key'] : ''); 575 576 $general_settings['hit_cp_auto_test'] = sanitize_text_field(isset($_POST['hit_cp_auto_test']) ? 'yes' : 'no'); … … 594 595 $general_settings['hit_cp_auto_developer_rate'] = sanitize_text_field(isset($_POST['hit_cp_auto_developer_rate']) ? 'yes' :'no'); 595 596 $general_settings['hit_cp_auto_rates_with_tax'] = sanitize_text_field(isset($_POST['hit_cp_auto_rates_with_tax']) ? 'yes' :'no'); 597 $general_settings['hit_cp_auto_rates_with_duties'] = sanitize_text_field(isset($_POST['hit_cp_auto_rates_with_duties']) ? 'yes' :'no'); 596 598 $general_settings['hit_cp_auto_insure'] = sanitize_text_field(isset($_POST['hit_cp_auto_insure']) ? 'yes' :'no'); 597 599 $general_settings['hit_cp_auto_exclude_countries'] = !empty($_POST['hit_cp_auto_exclude_countries']) ? $_POST['hit_cp_auto_exclude_countries'] : array(); … … 880 882 </tr> 881 883 <tr> 884 <td style=" width: 50%;padding:10px;"> 885 <?php _e('Zonos Account Key (Required for US Shipping)','hit_cp_auto') ?> 886 <input type="text" class="input-text regular-input" name="hit_cp_auto_zonos_acc_no" id="hit_cp_auto_zonos_acc_no" value="<?php echo (isset($general_settings['hit_cp_auto_zonos_acc_no'])) ? $general_settings['hit_cp_auto_zonos_acc_no'] : ''; ?>"> 887 </td> 882 888 <td style="padding:10px;"> 883 889 <?php _e('Weight Unit','hit_cp_auto') ?><br> … … 887 893 </select> 888 894 </td> 895 </tr> 896 <tr> 889 897 <td style="padding:10px;"> 890 <?php _e('Change Canada Post currency','hit_cp_auto') ?> 898 <?php _e('Change Canada Post currency','hit_cp_auto') ?><br> 891 899 <select name="hit_cp_auto_currency" style="width:95%;padding:5px;"> 892 900 … … 910 918 </select> 911 919 </td> 920 <td></td> 912 921 </tr> 913 922 <tr><td colspan="2" style="padding:10px;"><hr></td></tr> … … 1075 1084 <td><span style="float:right;padding-right:10px;"><input type="checkbox" name="hit_cp_auto_rates_with_tax" <?php echo (isset($general_settings['hit_cp_auto_rates_with_tax']) && $general_settings['hit_cp_auto_rates_with_tax'] == 'yes') ? 'checked="true"' : ''; ?> value="yes" ><small style="color:gray">Show rates including tax, surcharge and discounts.</small></span></td> 1076 1085 <td><span style="float:right;padding-right:10px;"><input type="checkbox" name="hit_cp_auto_insure" <?php echo (isset($general_settings['hit_cp_auto_insure']) && $general_settings['hit_cp_auto_insure'] == 'yes') ? 'checked="true"' : ''; ?> value="yes" ><small style="color:gray"> Canada Post Insurance.</small></span></td> 1086 <td><span style="float:right;padding-right:10px;"><input type="checkbox" name="hit_cp_auto_rates_with_duties" <?php echo (isset($general_settings['hit_cp_auto_rates_with_duties']) && $general_settings['hit_cp_auto_rates_with_duties'] == 'yes') ? 'checked="true"' : ''; ?> value="yes" ><small style="color:gray">Show rates including custom duties.</small></span></td> 1077 1087 </table> 1078 1088 -
a2z-canada-post-automated-shipping/trunk/hit_canadapost_auto_basic.php
r3374567 r3404922 4 4 * Plugin URI: https://wordpress.org/plugins/a2z-canada-post-automated-shipping/#developers 5 5 * Description: Realtime Shipping Rates, Shipping label, commercial invoice automation included. 6 * Version: 3. 0.46 * Version: 3.1.0 7 7 * Author: Shipi 8 8 * Author URI: https://myshipi.com/ … … 76 76 add_action( 'admin_menu', array($this, 'hit_cp_menu_page' )); 77 77 add_action( 'woocommerce_order_status_processing', array( $this, 'hit_wc_checkout_order_processed' ) ); 78 add_filter( 'woocommerce_product_data_tabs', array($this,'hit_product_data_tab') ); 79 add_action( 'woocommerce_process_product_meta', array($this,'hit_save_product_options' )); 80 add_filter( 'woocommerce_product_data_panels', array($this,'hit_product_option_view') ); 78 81 // add_action( 'woocommerce_thankyou', array( $this, 'hit_wc_checkout_order_processed' ) ); 79 82 … … 409 412 return $link; 410 413 } 414 public function hit_product_data_tab( $tabs) { 415 416 $tabs['hits_cp_product_options'] = array( 417 'label' => __( 'Shipi - Canada Post Options', 'hit_cp_auto' ), 418 'target' => 'hit_cp_product_options', 419 ); 420 421 return $tabs; 422 423 } 424 public function hit_save_product_options( $post_id ){ 425 if( isset($_POST['hits_cp_hs_code']) ){ 426 $cc = sanitize_text_field($_POST['hits_cp_hs_code']); 427 if ($this->hpos_enabled && $this->new_prod_editor_enabled) { 428 $hpos_prod_data = wc_get_product($post_id); 429 $cp_account = $hpos_prod_data->update_meta_data("hits_cp_hs_code", (string) esc_html( $cc )); 430 } else { 431 update_post_meta( $post_id, 'hits_cp_hs_code', (string) esc_html( $cc ) ); 432 } 433 } 434 } 435 public function hit_product_option_view(){ 436 global $woocommerce, $post; 437 if ($this->hpos_enabled) { 438 $hpos_prod_data = wc_get_product($post->ID); 439 $hits_cp_saved_hs_code = $hpos_prod_data->get_meta("hits_cp_hs_code"); 440 } 441 ?> 442 <div id='hit_cp_product_options' class='panel woocommerce_options_panel'> 443 <div class='options_group'> 444 <p class="form-field"> 445 <label for="hits_cp_hs_code"><?php _e( 'Enter HS code', 'hit_cp_auto' ); ?></label> 446 <span class='woocommerce-help-tip' data-tip="<?php _e('Enter HS code for product (20 charcters max).','hit_cp_auto') ?>"></span> 447 <input type='text' id='hits_cp_hs_code' name='hits_cp_hs_code' <?php echo (!empty($hits_cp_saved_hs_code) ? 'value="'.$hits_cp_saved_hs_code.'"' : '');?> style="width: 90%;"> 448 </p> 449 </div> 450 </div> 451 <?php 452 } 453 411 454 public function hit_wc_checkout_order_processed($order_id){ 412 455 $general_settings = get_option('hit_cp_auto_main_settings',array()); … … 609 652 "password" => $general_settings['hit_cp_auto_site_pwd'], 610 653 "accountnum" => $general_settings['hit_cp_auto_acc_no'], 654 "zonos_account_key" => isset($general_settings['hit_cp_auto_zonos_acc_no']) ? $general_settings['hit_cp_auto_zonos_acc_no'] : '', 611 655 "contractId" => $general_settings['hit_cp_auto_access_key'], 612 656 "t_company" => $order_shipping_company, … … 828 872 "password" => $general_settings['hit_cp_auto_site_pwd'], 829 873 "accountnum" => $general_settings['hit_cp_auto_acc_no'], 874 "zonos_account_key" => isset($general_settings['hit_cp_auto_zonos_acc_no']) ? $general_settings['hit_cp_auto_zonos_acc_no'] : '', 830 875 "contractId" => $general_settings['hit_cp_auto_access_key'], 831 876 "t_company" => $order_shipping_company, … … 878 923 "label" => "default", 879 924 ); 925 880 926 //manual 881 927 $manual_ship_url = "https://app.myshipi.com/label_api/create_shipment.php"; -
a2z-canada-post-automated-shipping/trunk/readme.txt
r3374567 r3404922 5 5 Tested up to: 6.8 6 6 Requires PHP: 5.6 7 Stable tag: 3. 0.47 Stable tag: 3.1.0 8 8 License: GPLv3 or later License 9 9 URI: http://www.gnu.org/licenses/gpl-3.0.html … … 80 80 81 81 == Changelog == 82 = 3.1.0 = 83 > Added Zonos Integration 84 82 85 = 3.0.4 = 83 86 > Added Tracking Status
Note: See TracChangeset
for help on using the changeset viewer.