Plugin Directory

Changeset 3404922


Ignore:
Timestamp:
11/28/2025 09:01:53 AM (6 weeks ago)
Author:
aarsiv
Message:

customs reate implmented

Location:
a2z-canada-post-automated-shipping/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • a2z-canada-post-automated-shipping/trunk/controllors/hit_canadapost_auto_init.php

    r3347108 r3404922  
    297297           
    298298            $des_coun = $pack_aft_hook['destination']['country'];
     299            $from_coun = $general_settings['hit_cp_auto_country'];
    299300            $orderCurrency = $value[$des_coun]['currency'];
     301            $zonos_rates_key = 'credential_live_d12bd9d7-de0d-4f9b-aeb8-254141252144'; 
    300302
    301303            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']))
     
    392394                           
    393395                            // 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                            // }
    404406                           
    405407                            // Insurance
     
    559561                                    if($rate_cost > 0)
    560562                                    {
    561                                    
    562563                                        $rate_name = $_carriers[$rate_code];
    563564                                        $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
    566575                                        $rate = array(
    567576                                            'id'       => 'hits'.$rate_code,
     
    978987         }
    979988
    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        }
    9821075    }
     1076}
  • a2z-canada-post-automated-shipping/trunk/controllors/views/hit_canadapost_auto_settings_view.php

    r3347096 r3404922  
    572572        $general_settings['hit_cp_auto_site_pwd'] = sanitize_text_field(isset($_POST['hit_cp_auto_site_pwd']) ? $_POST['hit_cp_auto_site_pwd'] : '');
    573573        $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'] : '');
    574575        $general_settings['hit_cp_auto_access_key'] = sanitize_text_field(isset($_POST['hit_cp_auto_access_key']) ? $_POST['hit_cp_auto_access_key'] : '');
    575576        $general_settings['hit_cp_auto_test'] = sanitize_text_field(isset($_POST['hit_cp_auto_test']) ? 'yes' : 'no');
     
    594595        $general_settings['hit_cp_auto_developer_rate'] = sanitize_text_field(isset($_POST['hit_cp_auto_developer_rate']) ? 'yes' :'no');
    595596        $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');
    596598        $general_settings['hit_cp_auto_insure'] = sanitize_text_field(isset($_POST['hit_cp_auto_insure']) ? 'yes' :'no');
    597599        $general_settings['hit_cp_auto_exclude_countries'] = !empty($_POST['hit_cp_auto_exclude_countries']) ? $_POST['hit_cp_auto_exclude_countries'] : array();
     
    880882            </tr>
    881883            <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>
    882888                <td style="padding:10px;">
    883889                <?php _e('Weight Unit','hit_cp_auto') ?><br>
     
    887893                    </select>
    888894                </td>
     895            </tr>
     896            <tr>
    889897                <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>
    891899                    <select name="hit_cp_auto_currency" style="width:95%;padding:5px;">
    892900                           
     
    910918                    </select>
    911919                </td>
     920                <td></td>
    912921            </tr>
    913922            <tr><td colspan="2" style="padding:10px;"><hr></td></tr>
     
    10751084        <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>
    10761085        <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>
    10771087        </table>
    10781088
  • a2z-canada-post-automated-shipping/trunk/hit_canadapost_auto_basic.php

    r3374567 r3404922  
    44 * Plugin URI: https://wordpress.org/plugins/a2z-canada-post-automated-shipping/#developers
    55 * Description: Realtime Shipping Rates, Shipping label, commercial invoice automation included.
    6  * Version: 3.0.4
     6 * Version: 3.1.0
    77 * Author: Shipi
    88 * Author URI: https://myshipi.com/
     
    7676                add_action( 'admin_menu', array($this, 'hit_cp_menu_page' ));
    7777                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') );
    7881                // add_action( 'woocommerce_thankyou', array( $this, 'hit_wc_checkout_order_processed' ) );
    7982           
     
    409412                return $link;
    410413            }
     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
    411454            public function hit_wc_checkout_order_processed($order_id){
    412455                $general_settings = get_option('hit_cp_auto_main_settings',array());
     
    609652                        "password"  => $general_settings['hit_cp_auto_site_pwd'],
    610653                        "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'] : '',
    611655                        "contractId" => $general_settings['hit_cp_auto_access_key'],
    612656                        "t_company" => $order_shipping_company,
     
    828872                                "password"  => $general_settings['hit_cp_auto_site_pwd'],
    829873                                "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'] : '',
    830875                                "contractId" => $general_settings['hit_cp_auto_access_key'],
    831876                                "t_company" => $order_shipping_company,
     
    878923                                "label" => "default",
    879924                            );
     925
    880926                            //manual
    881927                            $manual_ship_url = "https://app.myshipi.com/label_api/create_shipment.php";
  • a2z-canada-post-automated-shipping/trunk/readme.txt

    r3374567 r3404922  
    55Tested up to: 6.8
    66Requires PHP: 5.6
    7 Stable tag: 3.0.4
     7Stable tag: 3.1.0
    88License: GPLv3 or later License
    99URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    8080
    8181== Changelog ==
     82= 3.1.0 =
     83    > Added Zonos Integration
     84
    8285= 3.0.4 =
    8386    > Added Tracking Status
Note: See TracChangeset for help on using the changeset viewer.