hpos_enabled = true; } if (get_option("woocommerce_feature_product_block_editor_enabled") === "yes") { $this->new_prod_editor_enabled = true; } add_action('woocommerce_shipping_init', array($this, 'hit_ups_init')); add_action('init', array($this, 'hit_order_status_update')); add_filter('woocommerce_shipping_methods', array($this, 'hit_ups_method')); add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'hit_ups_plugin_action_links')); add_action('add_meta_boxes', array($this, 'create_ups_shipping_meta_box')); if ($this->hpos_enabled) { add_action( 'woocommerce_process_shop_order_meta', array($this, 'hit_create_ups_shipping'), 10, 1 ); add_action( 'woocommerce_process_shop_order_meta', array($this, 'create_ups_return_label'), 10, 1 ); } else { add_action('save_post', array($this, 'hit_create_ups_shipping'), 10, 1); add_action('save_post', array($this, 'create_ups_return_label'), 10, 1); } add_action('admin_menu', array($this, 'hit_ups_menu_page')); add_action('woocommerce_order_status_processing', array($this, 'hit_wc_checkout_order_processed')); // Background run of the auto label (Action Scheduler), see hit_wc_checkout_order_processed() add_action( 'a2z_ups_bg_auto_label', array( $this, 'hit_wc_checkout_order_processed' ) ); // add_action( 'woocommerce_checkout_order_processed', array( $this, 'hit_wc_checkout_order_processed' ) ); // add_action( 'woocommerce_thankyou', array( $this, 'hit_wc_checkout_order_processed' ) ); add_action('woocommerce_order_details_after_order_table', array($this, 'ups_track')); $general_settings = get_option('hit_ups_auto_main_settings'); $general_settings = empty($general_settings) ? array() : $general_settings; if (isset($general_settings['hit_ups_auto_v_enable']) && $general_settings['hit_ups_auto_v_enable'] == 'yes') { // add_action( 'woocommerce_product_options_shipping', array($this,'hit_choose_vendor_address' )); add_action('woocommerce_process_product_meta', array($this, 'hit_save_product_meta')); add_filter('woocommerce_product_data_tabs', array($this, 'custom_product_tabs')); // Edit User Hooks add_action('edit_user_profile', array($this, 'hit_define_ups_credentails')); add_action('edit_user_profile_update', array($this, 'save_user_fields')); add_filter('woocommerce_product_data_panels', array($this, 'hit_choose_vendor_address')); // WC 2.6 and up } } function hit_ups_menu_page() { $general_settings = get_option('hit_ups_auto_main_settings'); if (isset($general_settings['hit_ups_auto_integration_key']) && !empty($general_settings['hit_ups_auto_integration_key'])) { add_menu_page(__( 'UPS Labels', 'hit_ups_auto' ), 'UPS Labels', 'manage_options', 'hit-ups-labels', array($this,'my_label_page_contents'), '', 6); } add_submenu_page('options-general.php', 'UPS Config', 'UPS Config', 'manage_options', 'hit-ups-configuration', array($this, 'my_admin_page_contents')); } function my_label_page_contents(){ $general_settings = get_option('hit_ups_auto_main_settings'); $url = site_url(); if (isset($general_settings['hit_ups_auto_integration_key']) && !empty($general_settings['hit_ups_auto_integration_key'])) { echo ""; } } function my_admin_page_contents() { include_once('controllors/views/hit_ups_automated_settings_view.php'); } function custom_product_tabs($tabs) { $tabs['ups'] = array( 'label' => __('UPS ACCOUNTS', 'woocommerce'), 'target' => 'ups_account', 'class' => array('show_if_simple', 'show_if_variable'), ); return $tabs; } public function ups_track($order) { $general_settings = get_option('hit_ups_auto_main_settings', array()); $order_id = $order->get_id(); $json_data = get_option('hit_ups_auto_values_' . $order_id); if (!empty($json_data) && isset($general_settings['hit_ups_auto_trk_status_cus']) && $general_settings['hit_ups_auto_trk_status_cus'] == "yes") { $array_data_to_track = json_decode($json_data, true); $track_datas = array(); if (isset($array_data_to_track[0])) { $track_datas = $array_data_to_track; } else { $track_datas[] = $array_data_to_track; } $trk_count = 1; $tot_trk_count = count($track_datas); if ($track_datas) { _e('
' . $event_date . '
' . $event_time . '
' . $event_status . '
' . $event_loc . ' , ' . $event_country . '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
" . $notice . "
",'hit_ups_auto'); delete_option('hit_ups_auto_status_' . $order_id); } if (!empty($json_data)) { $array_data = json_decode($json_data, true); if (isset($array_data[0])) { foreach ($array_data as $key => $value) { if (isset($value['user_id'])) { unset($custom_settings[$value['user_id']]); } if (isset($value['user_id']) && $value['user_id'] == 'default') { _e('| ",'hit_ups_auto'); _e(" | " . substr($product_data['name'], 0, 7) . " | ",'hit_ups_auto'); _e("",'hit_ups_auto'); _e(" |
" . $notice . "
",'hit_ups_auto'); delete_option('hit_ups_auto_return_status_' . $order_id); } _e('','hit_ups_auto'); } else { $array_data = json_decode($json_data, true); $labels = explode(',', $array_data[0]['label']); foreach ($labels as $count => $label) { _e(' Return Label ' . ($count + 1) . ' ','hit_ups_auto'); } _e(' Invoice ','hit_ups_auto'); _e('','hit_ups_auto'); } } public function hit_wc_checkout_order_processed($order_id) { // Don't create the label inside the shopper's checkout request: queue it in WooCommerce's // Action Scheduler and run it right after, in the background. Without Action Scheduler // (very old WooCommerce) it runs now, as before. if ( ! empty( $order_id ) && ! doing_action( 'a2z_ups_bg_auto_label' ) && function_exists( 'as_enqueue_async_action' ) ) { if ( ! function_exists( 'as_has_scheduled_action' ) || ! as_has_scheduled_action( 'a2z_ups_bg_auto_label', array( (int) $order_id ), 'shipi' ) ) { as_enqueue_async_action( 'a2z_ups_bg_auto_label', array( (int) $order_id ), 'shipi' ); } return; } $_ups_carriers = array( //"Public carrier name" => "technical name", 'ups_12' => '3 Day Select', 'ups_03' => 'Ground', 'ups_02' => '2nd Day Air', 'ups_59' => '2nd Day Air AM', 'ups_01' => 'Next Day Air', 'ups_13' => 'Next Day Air Saver', 'ups_14' => 'Next Day Air Early AM', 'ups_11' => 'UPS Standard', 'ups_07' => 'UPS Express', 'ups_08' => 'UPS Expedited', 'ups_54' => 'UPS Express Plus', 'ups_65' => 'UPS Saver', 'ups_92' => 'SurePost Less than 1 lb', 'ups_93' => 'SurePost 1 lb or Greater', 'ups_94' => 'SurePost BPM', 'ups_95' => 'SurePost Media', 'ups_08' => 'UPS ExpeditedSM', 'ups_82' => 'Today Standard', "ups_83" => "UPS Today Dedicated Courier", "ups_84" => "UPS Today Intercity", "ups_85" => "UPS Today Express", "ups_86" => "UPS Today Express Saver", 'ups_M2' => 'First Class Mail', 'ups_M3' => 'Priority Mail', 'ups_M4' => 'Expedited Mail Innovations', 'ups_M5' => 'Priority Mail Innovations', 'ups_M6' => 'EconomyMail Innovations', 'ups_70' => 'Access Point Economy', 'ups_96' => 'Worldwide Express Freight' ); if ($this->hpos_enabled) { if ('shop_order' !== Automattic\WooCommerce\Utilities\OrderUtil::get_order_type($order_id)) { return; } } else { $post = get_post($order_id); if ($post->post_type != 'shop_order') { return; } } $ship_content = !empty($_POST['hit_ups_auto_shipment_content']) ? sanitize_text_field($_POST['hit_ups_auto_shipment_content']) : 'Shipment Content'; $order = wc_get_order($order_id); $service_code = $multi_ven = ''; foreach ($order->get_shipping_methods() as $item_id => $item) { $service_nme = $item->get_meta('hit_ups_auto_service'); $service_code = str_replace("ups_", "", $service_nme); $multi_ven = $item->get_meta('a2z_multi_ven'); } $order_data = $order->get_data(); $order_id = $order_data['id']; $order_currency = $order_data['currency']; // $order_shipping_first_name = $order_data['shipping']['first_name']; // $order_shipping_last_name = $order_data['shipping']['last_name']; // $order_shipping_company = empty($order_data['shipping']['company']) ? $order_data['shipping']['first_name'] : $order_data['shipping']['company']; // $order_shipping_address_1 = $order_data['shipping']['address_1']; // $order_shipping_address_2 = $order_data['shipping']['address_2']; // $order_shipping_city = $order_data['shipping']['city']; // $order_shipping_state = $order_data['shipping']['state']; // $order_shipping_postcode = $order_data['shipping']['postcode']; // $order_shipping_country = $order_data['shipping']['country']; // $order_shipping_phone = $order_data['billing']['phone']; // $order_shipping_email = $order_data['billing']['email']; $shipping_arr = (isset($order_data['shipping']['first_name']) && $order_data['shipping']['first_name'] != "") ? $order_data['shipping'] : $order_data['billing']; $order_shipping_first_name = $shipping_arr['first_name']; $order_shipping_last_name = $shipping_arr['last_name']; $order_shipping_company = empty($shipping_arr['company']) ? $shipping_arr['first_name'] : $shipping_arr['company']; $order_shipping_address_1 = $shipping_arr['address_1']; $order_shipping_address_2 = $shipping_arr['address_2']; $order_shipping_city = $shipping_arr['city']; $order_shipping_state = $shipping_arr['state']; $order_shipping_postcode = $shipping_arr['postcode']; $order_shipping_country = $shipping_arr['country']; $order_shipping_phone = $order_data['billing']['phone']; $order_shipping_email = $order_data['billing']['email']; $items = $order->get_items(); $pack_products = array(); $total_weg = 0; //weight conversion wc_get_weight( $weight, $to_unit, $from_unit ) $general_settings = get_option('hit_ups_auto_main_settings', array()); if (!isset($general_settings['hit_ups_auto_label_automation']) || (isset($general_settings['hit_ups_auto_label_automation']) && $general_settings['hit_ups_auto_label_automation'] != "yes")) { return false; } $woo_weg_unit = get_option('woocommerce_weight_unit'); $woo_dim_unit = get_option('woocommerce_dimension_unit'); $config_weg_unit = $general_settings['hit_ups_auto_weight_unit']; $custom_settings = array(); $custom_settings['default'] = array( 'hit_ups_auto_site_id' => $general_settings['hit_ups_auto_site_id'], 'hit_ups_auto_site_pwd' => $general_settings['hit_ups_auto_site_pwd'], 'hit_ups_auto_acc_no' => $general_settings['hit_ups_auto_acc_no'], 'hit_ups_auto_access_key' => $general_settings['hit_ups_auto_access_key'], 'hit_ups_auto_rest_site_id' => isset($general_settings['hit_ups_auto_rest_site_id']) ? $general_settings['hit_ups_auto_rest_site_id'] : '', 'hit_ups_auto_rest_site_pwd' => isset($general_settings['hit_ups_auto_rest_site_pwd']) ? $general_settings['hit_ups_auto_rest_site_pwd'] : '', 'hit_ups_auto_rest_acc_no' => isset($general_settings['hit_ups_auto_rest_acc_no']) ? $general_settings['hit_ups_auto_rest_acc_no'] : '', 'hit_ups_auto_rest_grant_type' => isset($general_settings['hit_ups_auto_rest_grant_type']) ? $general_settings['hit_ups_auto_rest_grant_type'] : '', 'hit_ups_auto_shipper_name' => $general_settings['hit_ups_auto_shipper_name'], 'hit_ups_auto_company' => $general_settings['hit_ups_auto_company'], 'hit_ups_auto_mob_num' => $general_settings['hit_ups_auto_mob_num'], 'hit_ups_auto_email' => $general_settings['hit_ups_auto_email'], 'hit_ups_auto_address1' => $general_settings['hit_ups_auto_address1'], 'hit_ups_auto_address2' => $general_settings['hit_ups_auto_address2'], 'hit_ups_auto_city' => $general_settings['hit_ups_auto_city'], 'hit_ups_auto_state' => $general_settings['hit_ups_auto_state'], 'hit_ups_auto_zip' => $general_settings['hit_ups_auto_zip'], 'hit_ups_auto_country' => $general_settings['hit_ups_auto_country'], 'hit_ups_auto_gstin' => $general_settings['hit_ups_auto_gstin'], 'hit_ups_auto_con_rate' => $general_settings['hit_ups_auto_con_rate'], 'service_code' => $service_code, 'hit_ups_auto_label_email' => $general_settings['hit_ups_auto_label_email'], 'hit_ups_auto_ven_col_type' => isset($general_settings['hit_ups_auto_ven_col_type']) ? $general_settings['hit_ups_auto_ven_col_type'] : "", 'hit_ups_auto_ven_col_id' => isset($general_settings['hit_ups_auto_ven_col_id']) ? $general_settings['hit_ups_auto_ven_col_id'] : "", ); $vendor_settings = array(); $mod_weg_unit = (!empty($config_weg_unit) && $config_weg_unit == 'LB_IN') ? 'lbs' : 'kg'; $mod_dim_unit = (!empty($config_weg_unit) && $config_weg_unit == 'LB_IN') ? 'in' : 'cm'; foreach ($items as $item) { $product_data = $item->get_data(); $product = array(); $product['product_name'] = $product_data['name']; $product['product_quantity'] = $product_data['quantity']; $product['product_id'] = $product_data['product_id']; $product_variation_id = $item->get_variation_id(); if (empty($product_variation_id)) { $getproduct = wc_get_product($product_data['product_id']); } else { $getproduct = wc_get_product($product_variation_id); } $product['price'] = $getproduct->get_price(); $product['width'] = !empty($getproduct->get_width()) ? round(wc_get_dimension($getproduct->get_width(), $mod_dim_unit, $woo_dim_unit)) : 0.5; $product['height'] = !empty($getproduct->get_height()) ? round(wc_get_dimension($getproduct->get_height(), $mod_dim_unit, $woo_dim_unit)) : 0.5; $product['depth'] = !empty($getproduct->get_length()) ? round(wc_get_dimension($getproduct->get_length(), $mod_dim_unit, $woo_dim_unit)) : 0.5; $product['weight'] = !empty($getproduct->get_weight()) ? (float)round(wc_get_weight($getproduct->get_weight(), $mod_weg_unit, $woo_weg_unit), 2) : 0.5; $total_weg += $product['weight']; $pack_products[] = $product; } if (isset($general_settings['hit_ups_auto_v_enable']) && $general_settings['hit_ups_auto_v_enable'] == 'yes' && isset($general_settings['hit_ups_auto_v_labels']) && $general_settings['hit_ups_auto_v_labels'] == 'yes') { // Multi Vendor Enabled foreach ($pack_products as $key => $value) { $product_id = $value['product_id']; if ($this->hpos_enabled) { $hpos_prod_data = wc_get_product($product_id); $ups_account = $hpos_prod_data->get_meta("hit_ups_auto_address"); } else { $ups_account = get_post_meta($product_id, 'hit_ups_auto_address', true); } if (empty($ups_account) || $ups_account == 'default') { $ups_account = 'default'; if (!isset($vendor_settings[$ups_account])) { $vendor_settings[$ups_account] = $custom_settings['default']; } $vendor_settings[$ups_account]['products'][] = $value; } if ($ups_account != 'default') { $user_account = get_post_meta($ups_account, 'hit_ups_auto_vendor_settings', true); $user_account = empty($user_account) ? array() : $user_account; if (!empty($user_account)) { if (!isset($vendor_settings[$ups_account])) { $vendor_settings[$ups_account] = $custom_settings['default']; if ($user_account['hit_ups_auto_site_id'] != '' && $user_account['hit_ups_auto_site_pwd'] != '' && $user_account['hit_ups_auto_acc_no'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_site_id'] = $user_account['hit_ups_auto_site_id']; if ($user_account['hit_ups_auto_site_pwd'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_site_pwd'] = $user_account['hit_ups_auto_site_pwd']; } if ($user_account['hit_ups_auto_acc_no'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_acc_no'] = $user_account['hit_ups_auto_acc_no']; } $vendor_settings[$ups_account]['hit_ups_auto_access_key'] = !empty($user_account['hit_ups_auto_access_key']) ? $user_account['hit_ups_auto_access_key'] : ''; } // REST credentials $vendor_settings[$ups_account]['hit_ups_auto_rest_site_id'] = isset($user_account['hit_ups_auto_rest_site_id']) ? $user_account['hit_ups_auto_rest_site_id'] : ""; $vendor_settings[$ups_account]['hit_ups_auto_rest_site_pwd'] = isset($user_account['hit_ups_auto_rest_site_pwd']) ? $user_account['hit_ups_auto_rest_site_pwd'] : ""; $vendor_settings[$ups_account]['hit_ups_auto_rest_acc_no'] = isset($user_account['hit_ups_auto_rest_acc_no']) ? $user_account['hit_ups_auto_rest_acc_no'] : ""; $vendor_settings[$ups_account]['hit_ups_auto_rest_grant_type'] = isset($user_account['hit_ups_auto_rest_grant_type']) ? $user_account['hit_ups_auto_rest_grant_type'] : "client_credentials"; if ($user_account['hit_ups_auto_address1'] != '' && $user_account['hit_ups_auto_city'] != '' && $user_account['hit_ups_auto_state'] != '' && $user_account['hit_ups_auto_zip'] != '' && $user_account['hit_ups_auto_country'] != '' && $user_account['hit_ups_auto_shipper_name'] != '') { if ($user_account['hit_ups_auto_shipper_name'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_shipper_name'] = $user_account['hit_ups_auto_shipper_name']; } if ($user_account['hit_ups_auto_company'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_company'] = $user_account['hit_ups_auto_company']; } if ($user_account['hit_ups_auto_mob_num'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_mob_num'] = $user_account['hit_ups_auto_mob_num']; } if ($user_account['hit_ups_auto_email'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_email'] = $user_account['hit_ups_auto_email']; } if ($user_account['hit_ups_auto_address1'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_address1'] = $user_account['hit_ups_auto_address1']; } $vendor_settings[$ups_account]['hit_ups_auto_address2'] = $user_account['hit_ups_auto_address2']; if ($user_account['hit_ups_auto_city'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_city'] = $user_account['hit_ups_auto_city']; } if ($user_account['hit_ups_auto_state'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_state'] = $user_account['hit_ups_auto_state']; } if ($user_account['hit_ups_auto_zip'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_zip'] = $user_account['hit_ups_auto_zip']; } if ($user_account['hit_ups_auto_country'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_country'] = $user_account['hit_ups_auto_country']; } $vendor_settings[$ups_account]['hit_ups_auto_gstin'] = $user_account['hit_ups_auto_gstin']; $vendor_settings[$ups_account]['hit_ups_auto_con_rate'] = $user_account['hit_ups_auto_con_rate']; if (isset($user_account['hit_ups_auto_ven_col_type']) && isset($user_account['hit_ups_auto_ven_col_id']) && !empty($user_account['hit_ups_auto_ven_col_id'])) { $vendor_settings[$ups_account]['hit_ups_auto_ven_col_type'] = $user_account['hit_ups_auto_ven_col_type']; $vendor_settings[$ups_account]['hit_ups_auto_ven_col_id'] = $user_account['hit_ups_auto_ven_col_id']; } } if (isset($general_settings['hit_ups_auto_v_email']) && $general_settings['hit_ups_auto_v_email'] == 'yes') { $user_dat = get_userdata($ups_account); $vendor_settings[$ups_account]['hit_ups_auto_label_email'] = $user_dat->data->user_email; } if ($multi_ven != '') { $array_ven = explode('|', $multi_ven); $scode = ''; foreach ($array_ven as $key => $svalue) { $ex_service = explode("_", $svalue); if ($ex_service[0] == $ups_account) { $vendor_settings[$ups_account]['service_code'] = $ex_service[1]; } } if ($scode == '') { if ($order_data['shipping']['country'] != $vendor_settings[$ups_account]['hit_ups_auto_country']) { $vendor_settings[$ups_account]['service_code'] = $user_account['hit_ups_auto_def_inter']; } else { $vendor_settings[$ups_account]['service_code'] = $user_account['hit_ups_auto_def_dom']; } } } else { if ($order_data['shipping']['country'] != $vendor_settings[$ups_account]['hit_ups_auto_country']) { $vendor_settings[$ups_account]['service_code'] = $user_account['hit_ups_auto_def_inter']; } else { $vendor_settings[$ups_account]['service_code'] = $user_account['hit_ups_auto_def_dom']; } } } unset($value['product_id']); $vendor_settings[$ups_account]['products'][] = $value; } } } } if (empty($vendor_settings)) { $custom_settings['default']['products'] = $pack_products; } else { $custom_settings = $vendor_settings; } $order_id = $order_data['id']; $order_currency = $order_data['currency']; // $order_shipping_first_name = $order_data['shipping']['first_name']; // $order_shipping_last_name = $order_data['shipping']['last_name']; // $order_shipping_company = empty($order_data['shipping']['company']) ? $order_data['shipping']['first_name'] : $order_data['shipping']['company']; // $order_shipping_address_1 = $order_data['shipping']['address_1']; // $order_shipping_address_2 = $order_data['shipping']['address_2']; // $order_shipping_city = $order_data['shipping']['city']; // $order_shipping_state = $order_data['shipping']['state']; // $order_shipping_postcode = $order_data['shipping']['postcode']; // $order_shipping_country = $order_data['shipping']['country']; // $order_shipping_phone = $order_data['billing']['phone']; // $order_shipping_email = $order_data['billing']['email']; $shipping_arr = (isset($order_data['shipping']['first_name']) && $order_data['shipping']['first_name'] != "") ? $order_data['shipping'] : $order_data['billing']; $order_shipping_first_name = $shipping_arr['first_name']; $order_shipping_last_name = $shipping_arr['last_name']; $order_shipping_company = empty($shipping_arr['company']) ? $shipping_arr['first_name'] : $shipping_arr['company']; $order_shipping_address_1 = $shipping_arr['address_1']; $order_shipping_address_2 = $shipping_arr['address_2']; $order_shipping_city = $shipping_arr['city']; $order_shipping_state = $shipping_arr['state']; $order_shipping_postcode = $shipping_arr['postcode']; $order_shipping_country = $shipping_arr['country']; $order_shipping_phone = $order_data['billing']['phone']; $order_shipping_email = $order_data['billing']['email']; $desination_country = (isset($order_data['shipping']['country']) && $order_data['shipping']['country'] != '') ? $order_data['shipping']['country'] : $order_data['billing']['country']; if (empty($service_code)) { if (!isset($general_settings['hit_ups_international_service']) && !isset($general_settings['hit_ups_Domestic_service'])) { return; } if (isset($general_settings['hit_ups_auto_country']) && $general_settings["hit_ups_auto_country"] == $desination_country && $general_settings['hit_ups_Domestic_service'] != 'null') { $service_code = str_replace("ups_", "", $general_settings['hit_ups_Domestic_service']); } elseif (isset($general_settings['hit_ups_auto_country']) && $general_settings["hit_ups_auto_country"] != $desination_country && $general_settings['hit_ups_international_service'] != 'null') { $service_code = str_replace("ups_", "", $general_settings['hit_ups_international_service']); } else { return; } } if (!empty($general_settings) && isset($general_settings['hit_ups_auto_integration_key'])) { $mode = 'live'; if (isset($general_settings['hit_ups_auto_test']) && $general_settings['hit_ups_auto_test'] == 'yes') { $mode = 'test'; } $execution = 'auto'; // if (isset($general_settings['hit_ups_auto_label_automation']) && $general_settings['hit_ups_auto_label_automation'] == 'yes') { // $execution = 'auto'; // } $pack_type = isset($_POST['hit_ups_auto_pack_type']) ? sanitize_text_field($_POST['hit_ups_auto_pack_type']) : '02'; $shipping_total = $order->get_shipping_total(); foreach ($custom_settings as $key => $cvalue) { $data = array(); $data['integrated_key'] = $general_settings['hit_ups_auto_integration_key']; $data['order_id'] = $order_id; $data['exec_type'] = $execution; $data['mode'] = $mode; $data['carrier_type'] = "UPS"; $data['ship_price'] = $order_data['shipping_total']; $data['acc_rates'] = ($general_settings['hit_ups_auto_account_rates'] == 'yes') ? "Y" : "N"; $data['meta'] = array( "site_id" => $cvalue['hit_ups_auto_site_id'], "password" => $cvalue['hit_ups_auto_site_pwd'], "accountnum" => $cvalue['hit_ups_auto_acc_no'], "site_acess" => $cvalue['hit_ups_auto_access_key'], "api_type" => isset($general_settings['hit_ups_auto_api_type']) ? $general_settings['hit_ups_auto_api_type'] : "SOAP", "rest_api_key" => isset($cvalue['hit_ups_auto_rest_site_id']) ? $cvalue['hit_ups_auto_rest_site_id'] : "", "rest_secret_key" => isset($cvalue['hit_ups_auto_rest_site_pwd']) ? $cvalue['hit_ups_auto_rest_site_pwd'] : "", "rest_acc_no" => isset($cvalue['hit_ups_auto_rest_acc_no']) ? $cvalue['hit_ups_auto_rest_acc_no'] : "", "rest_grant_type" => isset($cvalue['hit_ups_auto_rest_grant_type']) ? $cvalue['hit_ups_auto_rest_grant_type'] : "", "t_company" => $order_shipping_company, "t_address1" => $order_shipping_address_1, "t_address2" => $order_shipping_address_2, "t_city" => $order_shipping_city, "t_state" => $order_shipping_state, "t_postal" => $order_shipping_postcode, "t_country" => $order_shipping_country, "t_name" => $order_shipping_first_name . ' ' . $order_shipping_last_name, "t_phone" => $order_shipping_phone, "t_email" => $order_shipping_email, "dutiable" => $general_settings['hit_ups_auto_duty_payment'], "insurance" => $general_settings['hit_ups_auto_insure'], "pack_this" => "Y", "residential" => 'false', "drop_off_type" => "REGULAR_PICKUP", "packing_type" => $pack_type, "shipping_charge" => $shipping_total, "products" => $cvalue['products'], "pack_algorithm" => $general_settings['hit_ups_auto_packing_type'], "max_weight" => $general_settings['hit_ups_auto_max_weight'], "wight_dim_unit" => $general_settings['hit_ups_auto_weight_unit'], "plt" => ($general_settings['hit_ups_auto_ppt'] == 'yes') ? "Y" : "N", "simple_rate" => ($general_settings['hit_ups_auto_simple_rate'] == 'yes') ? "Y" : "N", "airway_bill" => ($general_settings['hit_ups_auto_aabill'] == 'yes') ? "Y" : "N", "sd" => ($general_settings['hit_ups_auto_sat'] == 'yes') ? "Y" : "N", "cod" => ($general_settings['hit_ups_auto_cod'] == 'yes') ? "Y" : "N", "service_code" => $service_code, "shipment_content" => $ship_content, "s_company" => $cvalue['hit_ups_auto_company'], "s_address1" => $cvalue['hit_ups_auto_address1'], "s_address2" => $cvalue['hit_ups_auto_address2'], "s_city" => $cvalue['hit_ups_auto_city'], "s_state" => $cvalue['hit_ups_auto_state'], "s_postal" => $cvalue['hit_ups_auto_zip'], "s_country" => $cvalue['hit_ups_auto_country'], "gstin" => $cvalue['hit_ups_auto_gstin'], "s_name" => $cvalue['hit_ups_auto_shipper_name'], "s_phone" => $cvalue['hit_ups_auto_mob_num'], "s_email" => $cvalue['hit_ups_auto_email'], "ven_col_type" => isset($cvalue['hit_ups_auto_ven_col_type']) ? $cvalue['hit_ups_auto_ven_col_type'] : "", "ven_col_id" => isset($cvalue['hit_ups_auto_ven_col_id']) ? $cvalue['hit_ups_auto_ven_col_id'] : "", "sig_req" => "", //$general_settings['hit_ups_auto_sign_req'], "label_format" => "GIF", "label_size" => $general_settings['hit_ups_auto_print_size'], "sent_email_to" => $cvalue['hit_ups_auto_label_email'], "del_con" => isset($general_settings['hit_ups_auto_del_con']) ? $general_settings['hit_ups_auto_del_con'] : "NONE", "label" => $key, "ref_no" => apply_filters('shipi_ref_no', '', $order_id) ); foreach ($data['meta']['products'] as $key => $value) { $data['meta']['products'][$key]['product_name'] = preg_replace('/[^\p{L}\s+\p{N}]/u', '', $value['product_name']); } // print_r(json_encode( $data)); // Auto Shipment // $auto_ship_url = "http://localhost/hitshipo/label_api/create_shipment.php"; $auto_ship_url = "https://app.myshipi.com/label_api/create_shipment.php"; wp_remote_post($auto_ship_url, array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => false, 'headers' => array('Content-Type' => 'application/json; charset=utf-8'), 'body' => json_encode($data), 'sslverify' => FALSE ) ); } } } // Save the data of the Meta field public function hit_create_ups_shipping($order_id) { if ($this->hpos_enabled) { if ('shop_order' !== Automattic\WooCommerce\Utilities\OrderUtil::get_order_type($order_id)) { return; } } else { $post = get_post($order_id); if ($post->post_type != 'shop_order') { return; } } if (isset($_POST['hit_ups_auto_reset'])) { delete_option('hit_ups_auto_values_' . $order_id); } if (isset($_POST['hit_ups_auto_create_label'])) { $create_shipment_for = sanitize_text_field($_POST['hit_ups_auto_create_label']); $service_code = str_replace("ups_", "", sanitize_text_field($_POST['hit_ups_auto_service_code_' . $create_shipment_for])); $ship_content = !empty($_POST['hit_ups_auto_shipment_content_' . $create_shipment_for]) ? sanitize_text_field($_POST['hit_ups_auto_shipment_content_' . $create_shipment_for]) : 'Shipment Content'; $order = wc_get_order($order_id); if ($order) { $order_data = $order->get_data(); $order_id = $order_data['id']; $order_currency = $order_data['currency']; // $order_shipping_first_name = $order_data['shipping']['first_name']; // $order_shipping_last_name = $order_data['shipping']['last_name']; // $order_shipping_company = empty($order_data['shipping']['company']) ? $order_data['shipping']['first_name'] : $order_data['shipping']['company']; // $order_shipping_address_1 = $order_data['shipping']['address_1']; // $order_shipping_address_2 = $order_data['shipping']['address_2']; // $order_shipping_city = $order_data['shipping']['city']; // $order_shipping_state = $order_data['shipping']['state']; // $order_shipping_postcode = $order_data['shipping']['postcode']; // $order_shipping_country = $order_data['shipping']['country']; // $order_shipping_phone = $order_data['billing']['phone']; // $order_shipping_email = $order_data['billing']['email']; $shipping_arr = (isset($order_data['shipping']['first_name']) && $order_data['shipping']['first_name'] != "") ? $order_data['shipping'] : $order_data['billing']; $order_shipping_first_name = $shipping_arr['first_name']; $order_shipping_last_name = $shipping_arr['last_name']; $order_shipping_company = empty($shipping_arr['company']) ? $shipping_arr['first_name'] : $shipping_arr['company']; $order_shipping_address_1 = $shipping_arr['address_1']; $order_shipping_address_2 = $shipping_arr['address_2']; $order_shipping_city = $shipping_arr['city']; $order_shipping_state = $shipping_arr['state']; $order_shipping_postcode = $shipping_arr['postcode']; $order_shipping_country = $shipping_arr['country']; $order_shipping_phone = $order_data['billing']['phone']; $order_shipping_email = $order_data['billing']['email']; $items = $order->get_items(); $pack_products = array(); $total_weg = 0; //weight conversion wc_get_weight( $weight, $to_unit, $from_unit ) $general_settings = get_option('hit_ups_auto_main_settings', array()); $woo_weg_unit = get_option('woocommerce_weight_unit'); $woo_dim_unit = get_option('woocommerce_dimension_unit'); $config_weg_unit = $general_settings['hit_ups_auto_weight_unit']; $mod_weg_unit = (!empty($config_weg_unit) && $config_weg_unit == 'LB_IN') ? 'lbs' : 'kg'; $mod_dim_unit = (!empty($config_weg_unit) && $config_weg_unit == 'LB_IN') ? 'in' : 'cm'; foreach ($items as $item) { $product_data = $item->get_data(); $product = array(); $product['product_name'] = $product_data['name']; $product['product_quantity'] = $product_data['quantity']; $product['product_id'] = $product_data['product_id']; $product_variation_id = $item->get_variation_id(); if (empty($product_variation_id)) { $getproduct = wc_get_product($product_data['product_id']); } else { $getproduct = wc_get_product($product_variation_id); } $product['price'] = $getproduct->get_price(); $product['width'] = !empty($getproduct->get_width()) ? round(wc_get_dimension($getproduct->get_width(), $mod_dim_unit, $woo_dim_unit)) : 0.5; $product['height'] = !empty($getproduct->get_height()) ? round(wc_get_dimension($getproduct->get_height(), $mod_dim_unit, $woo_dim_unit)) : 0.5; $product['depth'] = !empty($getproduct->get_length()) ? round(wc_get_dimension($getproduct->get_length(), $mod_dim_unit, $woo_dim_unit)) : 0.5; $product['weight'] = !empty($getproduct->get_weight()) ? (float)round(wc_get_weight($getproduct->get_weight(), $mod_weg_unit, $woo_weg_unit), 2) : 0.5; $total_weg += $product['weight']; $pack_products[] = $product; } $custom_settings = array(); $custom_settings['default'] = array( 'hit_ups_auto_site_id' => $general_settings['hit_ups_auto_site_id'], 'hit_ups_auto_site_pwd' => $general_settings['hit_ups_auto_site_pwd'], 'hit_ups_auto_acc_no' => $general_settings['hit_ups_auto_acc_no'], 'hit_ups_auto_access_key' => $general_settings['hit_ups_auto_access_key'], 'hit_ups_auto_rest_site_id' => isset($general_settings['hit_ups_auto_rest_site_id']) ? $general_settings['hit_ups_auto_rest_site_id'] : '', 'hit_ups_auto_rest_site_pwd' => isset($general_settings['hit_ups_auto_rest_site_pwd']) ? $general_settings['hit_ups_auto_rest_site_pwd'] : '', 'hit_ups_auto_rest_acc_no' => isset($general_settings['hit_ups_auto_rest_acc_no']) ? $general_settings['hit_ups_auto_rest_acc_no'] : '', 'hit_ups_auto_rest_grant_type' => isset($general_settings['hit_ups_auto_rest_grant_type']) ? $general_settings['hit_ups_auto_rest_grant_type'] : '', 'hit_ups_auto_shipper_name' => $general_settings['hit_ups_auto_shipper_name'], 'hit_ups_auto_company' => $general_settings['hit_ups_auto_company'], 'hit_ups_auto_mob_num' => $general_settings['hit_ups_auto_mob_num'], 'hit_ups_auto_email' => $general_settings['hit_ups_auto_email'], 'hit_ups_auto_address1' => $general_settings['hit_ups_auto_address1'], 'hit_ups_auto_address2' => $general_settings['hit_ups_auto_address2'], 'hit_ups_auto_city' => $general_settings['hit_ups_auto_city'], 'hit_ups_auto_state' => $general_settings['hit_ups_auto_state'], 'hit_ups_auto_zip' => $general_settings['hit_ups_auto_zip'], 'hit_ups_auto_country' => $general_settings['hit_ups_auto_country'], 'hit_ups_auto_gstin' => $general_settings['hit_ups_auto_gstin'], 'hit_ups_auto_con_rate' => $general_settings['hit_ups_auto_con_rate'], 'service_code' => $service_code, 'hit_ups_auto_label_email' => $general_settings['hit_ups_auto_label_email'], 'hit_ups_auto_ven_col_type' => isset($general_settings['hit_ups_auto_ven_col_type']) ? $general_settings['hit_ups_auto_ven_col_type'] : "", 'hit_ups_auto_ven_col_id' => isset($general_settings['hit_ups_auto_ven_col_id']) ? $general_settings['hit_ups_auto_ven_col_id'] : "", ); $vendor_settings = array(); if (isset($general_settings['hit_ups_auto_v_enable']) && $general_settings['hit_ups_auto_v_enable'] == 'yes' && isset($general_settings['hit_ups_auto_v_labels']) && $general_settings['hit_ups_auto_v_labels'] == 'yes') { // Multi Vendor Enabled foreach ($pack_products as $key => $value) { $product_id = $value['product_id']; if ($this->hpos_enabled) { $hpos_prod_data = wc_get_product($product_id); $ups_account = $hpos_prod_data->get_meta("hit_ups_auto_address"); } else { $ups_account = get_post_meta($product_id, 'hit_ups_auto_address', true); } if (empty($ups_account) || $ups_account == 'default') { $ups_account = 'default'; if (!isset($vendor_settings[$ups_account])) { $vendor_settings[$ups_account] = $custom_settings['default']; } $vendor_settings[$ups_account]['products'][] = $value; } if ($ups_account != 'default') { $user_account = get_post_meta($ups_account, 'hit_ups_auto_vendor_settings', true); $user_account = empty($user_account) ? array() : $user_account; if (!empty($user_account)) { if (!isset($vendor_settings[$ups_account])) { $vendor_settings[$ups_account] = $custom_settings['default']; if ($user_account['hit_ups_auto_site_id'] != '' && $user_account['hit_ups_auto_site_pwd'] != '' && $user_account['hit_ups_auto_acc_no'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_site_id'] = $user_account['hit_ups_auto_site_id']; if ($user_account['hit_ups_auto_site_pwd'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_site_pwd'] = $user_account['hit_ups_auto_site_pwd']; } if ($user_account['hit_ups_auto_acc_no'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_acc_no'] = $user_account['hit_ups_auto_acc_no']; } // $vendor_settings[$ups_account]['hit_ups_auto_access_key'] = !empty($user_account['hit_ups_auto_access_key']) ? $user_account['hit_ups_auto_access_key'] : ''; if ($user_account['hit_ups_auto_access_key'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_access_key'] = $user_account['hit_ups_auto_access_key']; } } // REST credentials $vendor_settings[$ups_account]['hit_ups_auto_rest_site_id'] = isset($user_account['hit_ups_auto_rest_site_id']) ? $user_account['hit_ups_auto_rest_site_id'] : ""; $vendor_settings[$ups_account]['hit_ups_auto_rest_site_pwd'] = isset($user_account['hit_ups_auto_rest_site_pwd']) ? $user_account['hit_ups_auto_rest_site_pwd'] : ""; $vendor_settings[$ups_account]['hit_ups_auto_rest_acc_no'] = isset($user_account['hit_ups_auto_rest_acc_no']) ? $user_account['hit_ups_auto_rest_acc_no'] : ""; $vendor_settings[$ups_account]['hit_ups_auto_rest_grant_type'] = isset($user_account['hit_ups_auto_rest_grant_type']) ? $user_account['hit_ups_auto_rest_grant_type'] : "client_credentials"; if ($user_account['hit_ups_auto_address1'] != '' && $user_account['hit_ups_auto_city'] != '' && $user_account['hit_ups_auto_state'] != '' && $user_account['hit_ups_auto_zip'] != '' && $user_account['hit_ups_auto_country'] != '' && $user_account['hit_ups_auto_shipper_name'] != '') { if ($user_account['hit_ups_auto_shipper_name'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_shipper_name'] = $user_account['hit_ups_auto_shipper_name']; } if ($user_account['hit_ups_auto_company'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_company'] = $user_account['hit_ups_auto_company']; } if ($user_account['hit_ups_auto_mob_num'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_mob_num'] = $user_account['hit_ups_auto_mob_num']; } if ($user_account['hit_ups_auto_email'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_email'] = $user_account['hit_ups_auto_email']; } if ($user_account['hit_ups_auto_address1'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_address1'] = $user_account['hit_ups_auto_address1']; } $vendor_settings[$ups_account]['hit_ups_auto_address2'] = $user_account['hit_ups_auto_address2']; if ($user_account['hit_ups_auto_city'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_city'] = $user_account['hit_ups_auto_city']; } if ($user_account['hit_ups_auto_state'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_state'] = $user_account['hit_ups_auto_state']; } if ($user_account['hit_ups_auto_zip'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_zip'] = $user_account['hit_ups_auto_zip']; } if ($user_account['hit_ups_auto_country'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_country'] = $user_account['hit_ups_auto_country']; } $vendor_settings[$ups_account]['hit_ups_auto_gstin'] = $user_account['hit_ups_auto_gstin']; $vendor_settings[$ups_account]['hit_ups_auto_con_rate'] = $user_account['hit_ups_auto_con_rate']; if (isset($user_account['hit_ups_auto_ven_col_type']) && isset($user_account['hit_ups_auto_ven_col_id']) && !empty($user_account['hit_ups_auto_ven_col_id'])) { $vendor_settings[$ups_account]['hit_ups_auto_ven_col_type'] = $user_account['hit_ups_auto_ven_col_type']; $vendor_settings[$ups_account]['hit_ups_auto_ven_col_id'] = $user_account['hit_ups_auto_ven_col_id']; } } if (isset($general_settings['hit_ups_auto_v_email']) && $general_settings['hit_ups_auto_v_email'] == 'yes') { $user_dat = get_userdata($ups_account); $vendor_settings[$ups_account]['hit_ups_auto_label_email'] = $user_dat->data->user_email; } if ($order_data['shipping']['country'] != $vendor_settings[$ups_account]['hit_ups_auto_country']) { $vendor_settings[$ups_account]['service_code'] = empty($service_code) ? $user_account['hit_ups_auto_def_inter'] : $service_code; } else { $vendor_settings[$ups_account]['service_code'] = empty($service_code) ? $user_account['hit_ups_auto_def_dom'] : $service_code; } } unset($value['product_id']); $vendor_settings[$ups_account]['products'][] = $value; } } } } if (empty($vendor_settings)) { $custom_settings['default']['products'] = $pack_products; } else { $custom_settings = $vendor_settings; } if (!empty($general_settings) && isset($general_settings['hit_ups_auto_integration_key']) && isset($custom_settings[$create_shipment_for])) { $mode = 'live'; if (isset($general_settings['hit_ups_auto_test']) && $general_settings['hit_ups_auto_test'] == 'yes') { $mode = 'test'; } $execution = 'manual'; // if (isset($general_settings['hit_ups_auto_label_automation']) && $general_settings['hit_ups_auto_label_automation'] == 'yes') { // $execution = 'auto'; // } $pack_type = isset($_POST['hit_ups_auto_pack_type']) ? sanitize_text_field($_POST['hit_ups_auto_pack_type']) : '02'; $shipping_total = $order->get_shipping_total(); $data = array(); $data['integrated_key'] = $general_settings['hit_ups_auto_integration_key']; $data['order_id'] = $order_id; $data['exec_type'] = $execution; $data['mode'] = $mode; $data['carrier_type'] = "UPS"; $data['ship_price'] = $order_data['shipping_total']; $data['acc_rates'] = ($general_settings['hit_ups_auto_account_rates'] == 'yes') ? "Y" : "N"; $data['meta'] = array( "site_id" => $custom_settings[$create_shipment_for]['hit_ups_auto_site_id'], "password" => $custom_settings[$create_shipment_for]['hit_ups_auto_site_pwd'], "accountnum" => $custom_settings[$create_shipment_for]['hit_ups_auto_acc_no'], "site_acess" => $custom_settings[$create_shipment_for]['hit_ups_auto_access_key'], "api_type" => isset($general_settings['hit_ups_auto_api_type']) ? $general_settings['hit_ups_auto_api_type'] : "SOAP", "rest_api_key" => isset($custom_settings[$create_shipment_for]['hit_ups_auto_rest_site_id']) ? $custom_settings[$create_shipment_for]['hit_ups_auto_rest_site_id'] : "", "rest_secret_key" => isset($custom_settings[$create_shipment_for]['hit_ups_auto_rest_site_pwd']) ? $custom_settings[$create_shipment_for]['hit_ups_auto_rest_site_pwd'] : "", "rest_acc_no" => isset($custom_settings[$create_shipment_for]['hit_ups_auto_rest_acc_no']) ? $custom_settings[$create_shipment_for]['hit_ups_auto_rest_acc_no'] : "", "rest_grant_type" => isset($custom_settings[$create_shipment_for]['hit_ups_auto_rest_grant_type']) ? $custom_settings[$create_shipment_for]['hit_ups_auto_rest_grant_type'] : "", "t_company" => $order_shipping_company, "t_address1" => $order_shipping_address_1, "t_address2" => $order_shipping_address_2, "t_city" => $order_shipping_city, "t_state" => $order_shipping_state, "t_postal" => $order_shipping_postcode, "t_country" => $order_shipping_country, "t_name" => $order_shipping_first_name . ' ' . $order_shipping_last_name, "t_phone" => $order_shipping_phone, "t_email" => $order_shipping_email, "dutiable" => $general_settings['hit_ups_auto_duty_payment'], "insurance" => $general_settings['hit_ups_auto_insure'], "pack_this" => "Y", "residential" => 'false', "drop_off_type" => "REGULAR_PICKUP", "packing_type" => $pack_type, "shipping_charge" => $shipping_total, "products" => $custom_settings[$create_shipment_for]['products'], "pack_algorithm" => $general_settings['hit_ups_auto_packing_type'], "max_weight" => $general_settings['hit_ups_auto_max_weight'], "wight_dim_unit" => $general_settings['hit_ups_auto_weight_unit'], "plt" => ($general_settings['hit_ups_auto_ppt'] == 'yes') ? "Y" : "N", "simple_rate" => ($general_settings['hit_ups_auto_simple_rate'] == 'yes') ? "Y" : "N", "airway_bill" => ($general_settings['hit_ups_auto_aabill'] == 'yes') ? "Y" : "N", "sd" => ($general_settings['hit_ups_auto_sat'] == 'yes') ? "Y" : "N", "cod" => ($general_settings['hit_ups_auto_cod'] == 'yes') ? "Y" : "N", "service_code" => str_replace('ups_', '', $custom_settings[$create_shipment_for]['service_code']), "shipment_content" => $ship_content, "s_company" => $custom_settings[$create_shipment_for]['hit_ups_auto_company'], "s_address1" => $custom_settings[$create_shipment_for]['hit_ups_auto_address1'], "s_address2" => $custom_settings[$create_shipment_for]['hit_ups_auto_address2'], "s_city" => $custom_settings[$create_shipment_for]['hit_ups_auto_city'], "s_state" => $custom_settings[$create_shipment_for]['hit_ups_auto_state'], "s_postal" => $custom_settings[$create_shipment_for]['hit_ups_auto_zip'], "s_country" => $custom_settings[$create_shipment_for]['hit_ups_auto_country'], "gstin" => $custom_settings[$create_shipment_for]['hit_ups_auto_gstin'], "s_name" => $custom_settings[$create_shipment_for]['hit_ups_auto_shipper_name'], "s_phone" => $custom_settings[$create_shipment_for]['hit_ups_auto_mob_num'], "s_email" => $custom_settings[$create_shipment_for]['hit_ups_auto_email'], "ven_col_type" => isset($custom_settings[$create_shipment_for]['hit_ups_auto_ven_col_type']) ? $custom_settings[$create_shipment_for]['hit_ups_auto_ven_col_type'] : "", "ven_col_id" => isset($custom_settings[$create_shipment_for]['hit_ups_auto_ven_col_id']) ? $custom_settings[$create_shipment_for]['hit_ups_auto_ven_col_id'] : "", "label_format" => "GIF", "sig_req" => "", "label_size" => $general_settings['hit_ups_auto_print_size'], "sent_email_to" => $custom_settings[$create_shipment_for]['hit_ups_auto_label_email'], "debug_log" => ($general_settings['hit_ups_auto_developer_rate'] == 'yes') ? 'Y' : 'N', "add_shipping_invoice_flag" => ($general_settings['hit_ups_add_shipping_invoice'] == "yes") ? 'Y' : 'N', "del_con" => isset($general_settings['hit_ups_auto_del_con']) ? $general_settings['hit_ups_auto_del_con'] : "NONE", "label" => $create_shipment_for, "ref_no" => apply_filters('shipi_ref_no', '', $order_id) ); foreach ($data['meta']['products'] as $key => $value) { $data['meta']['products'][$key]['product_name'] = preg_replace('/[^\p{L}\s+\p{N}]/u', '', $value['product_name']); } // Manual Shipment // $manual_ship_url = "http://localhost/hitshipo/api/ups_manual.php"; // $manual_ship_url = "http://localhost/hitshipo/label_api/create_shipment.php"; $manual_ship_url = "https://app.myshipi.com/label_api/create_shipment.php"; $response = wp_remote_post( $manual_ship_url , array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array('Content-Type' => 'application/json; charset=utf-8'), 'body' => json_encode($data), 'sslverify' => FALSE ) ); $output = (is_array($response) && isset($response['body'])) ? json_decode($response['body'],true) : []; if ($output) { if (isset($output['status'])) { if (isset($output['status']) && $output['status'] != 'success') { update_option('hit_ups_auto_status_' . $order_id, $output['status']); } else if (isset($output['status']) && $output['status'] == 'success') { $output['user_id'] = $create_shipment_for; $result_arr = []; $val = get_option('hit_ups_auto_values_' . $order_id, array()); if(!empty($val)){ $result_arr = json_decode($val, true); } $result_arr[] = $output; $order_status = apply_filters('hitshipo_ups_cus_order_status',''); if (!empty($order_status)) { $order = wc_get_order($order_id); $order->update_status($order_status); } update_option('hit_ups_auto_values_' . $order_id, json_encode($result_arr)); } else { update_option('hit_ups_auto_status_' . $order_id, "Unknown response found."); } } } else { update_option('hit_ups_auto_status_' . $order_id, 'Site not Connected with Shipi. Contact Shipi Team.'); } } } } } public function sanitize_array($string) { foreach ($string as $k => $v) { if (is_array($v)) { $string[$k] = $this->sanitize_array($v); } else { $string[$k] = sanitize_text_field($v); } } return $string; } public function create_ups_return_label($order_id) { if ($this->hpos_enabled) { if ('shop_order' !== Automattic\WooCommerce\Utilities\OrderUtil::get_order_type($order_id)) { return; } } else { $post = get_post($order_id); if ($post->post_type != 'shop_order') { return; } } if (isset($_POST['hit_ups_auto_return_reset'])) { delete_option('hit_ups_auto_return_values_' . $order_id); } if (isset($_POST['hit_ups_auto_create_return_label'])) { $create_shipment_for = sanitize_text_field($_POST['hit_ups_auto_create_return_label']); $service_code = str_replace("ups_", "", sanitize_text_field($_POST['hit_ups_auto_return_service_code_' . $create_shipment_for])); $ship_content = "Return Shipment"; $enabled_products = isset($_POST['return_products_ups']) ? $this->sanitize_array($_POST['return_products_ups']) : array(); $qty_products = isset($_POST['qty_products_ups']) ? $this->sanitize_array($_POST['qty_products_ups']) : array(); $order = wc_get_order($order_id); $order = wc_get_order($order_id); if ($order && !empty($enabled_products)) { $order_data = $order->get_data(); $order_id = $order_data['id']; $order_currency = $order_data['currency']; // $order_shipping_first_name = $order_data['shipping']['first_name']; // $order_shipping_last_name = $order_data['shipping']['last_name']; // $order_shipping_company = empty($order_data['shipping']['company']) ? $order_data['shipping']['first_name'] : $order_data['shipping']['company']; // $order_shipping_address_1 = $order_data['shipping']['address_1']; // $order_shipping_address_2 = $order_data['shipping']['address_2']; // $order_shipping_city = $order_data['shipping']['city']; // $order_shipping_state = $order_data['shipping']['state']; // $order_shipping_postcode = $order_data['shipping']['postcode']; // $order_shipping_country = $order_data['shipping']['country']; // $order_shipping_phone = $order_data['billing']['phone']; // $order_shipping_email = $order_data['billing']['email']; $shipping_arr = (isset($order_data['shipping']['first_name']) && $order_data['shipping']['first_name'] != "") ? $order_data['shipping'] : $order_data['billing']; $order_shipping_first_name = $shipping_arr['first_name']; $order_shipping_last_name = $shipping_arr['last_name']; $order_shipping_company = empty($shipping_arr['company']) ? $shipping_arr['first_name'] : $shipping_arr['company']; $order_shipping_address_1 = $shipping_arr['address_1']; $order_shipping_address_2 = $shipping_arr['address_2']; $order_shipping_city = $shipping_arr['city']; $order_shipping_state = $shipping_arr['state']; $order_shipping_postcode = $shipping_arr['postcode']; $order_shipping_country = $shipping_arr['country']; $order_shipping_phone = $order_data['billing']['phone']; $order_shipping_email = $order_data['billing']['email']; $items = $order->get_items(); $pack_products = array(); $total_weg = 0; //weight conversion wc_get_weight( $weight, $to_unit, $from_unit ) $general_settings = get_option('hit_ups_auto_main_settings', array()); $woo_weg_unit = get_option('woocommerce_weight_unit'); $woo_dim_unit = get_option('woocommerce_dimension_unit'); $config_weg_unit = $general_settings['hit_ups_auto_weight_unit']; $mod_weg_unit = (!empty($config_weg_unit) && $config_weg_unit == 'LB_IN') ? 'lbs' : 'kg'; $mod_dim_unit = (!empty($config_weg_unit) && $config_weg_unit == 'LB_IN') ? 'in' : 'cm'; foreach ($items as $item) { $product_data = $item->get_data(); $product = array(); $product['product_name'] = $product_data['name']; $product['product_quantity'] = $product_data['quantity']; $product['product_id'] = $product_data['product_id']; // if ($this->hpos_enabled) { // $hpos_prod_data = wc_get_product($product_data['product_id']); // $saved_cc = $hpos_prod_data->get_meta("hits_dhl_cc"); // } else { // $saved_cc = get_post_meta($product_data['product_id'], 'hits_dhl_cc', true); // } // if (!empty($saved_cc)) { // $product['commodity_code'] = $saved_cc; // } $product_variation_id = $item->get_variation_id(); $product_id = $product_data['product_id']; if (empty($product_variation_id)) { $getproduct = wc_get_product($product_data['product_id']); } else { $getproduct = wc_get_product($product_variation_id); $product_id = $product_variation_id; } if (!in_array($product_id, $enabled_products)) { continue; } else { if ($qty_products[$product_id] == 0) { continue; } else { $product['product_quantity'] = $qty_products[$product_id]; } } $product['price'] = $getproduct->get_price(); if (!$product['price']) { $product['price'] = (isset($product_data['total']) && isset($product_data['quantity'])) ? number_format(($product_data['total'] / $product_data['quantity']), 2) : 0; } $product['width'] = !empty($getproduct->get_width()) ? round(wc_get_dimension($getproduct->get_width(), $mod_dim_unit, $woo_dim_unit)) : 0.5; $product['height'] = !empty($getproduct->get_height()) ? round(wc_get_dimension($getproduct->get_height(), $mod_dim_unit, $woo_dim_unit)) : 0.5; $product['depth'] = !empty($getproduct->get_length()) ? round(wc_get_dimension($getproduct->get_length(), $mod_dim_unit, $woo_dim_unit)) : 0.5; $product['weight'] = !empty($getproduct->get_weight()) ? (float)round(wc_get_weight($getproduct->get_weight(), $mod_weg_unit, $woo_weg_unit), 2) : 0.5; $total_weg += $product['weight']; $pack_products[] = $product; $return_prod[] = $product; } $custom_settings = array(); $custom_settings['default'] = array( 'hit_ups_auto_site_id' => $general_settings['hit_ups_auto_site_id'], 'hit_ups_auto_site_pwd' => $general_settings['hit_ups_auto_site_pwd'], 'hit_ups_auto_acc_no' => $general_settings['hit_ups_auto_acc_no'], 'hit_ups_auto_access_key' => $general_settings['hit_ups_auto_access_key'], 'hit_ups_auto_rest_site_id' => isset($general_settings['hit_ups_auto_rest_site_id']) ? $general_settings['hit_ups_auto_rest_site_id'] : '', 'hit_ups_auto_rest_site_pwd' => isset($general_settings['hit_ups_auto_rest_site_pwd']) ? $general_settings['hit_ups_auto_rest_site_pwd'] : '', 'hit_ups_auto_rest_acc_no' => isset($general_settings['hit_ups_auto_rest_acc_no']) ? $general_settings['hit_ups_auto_rest_acc_no'] : '', 'hit_ups_auto_rest_grant_type' => isset($general_settings['hit_ups_auto_rest_grant_type']) ? $general_settings['hit_ups_auto_rest_grant_type'] : '', 'hit_ups_auto_shipper_name' => $general_settings['hit_ups_auto_shipper_name'], 'hit_ups_auto_company' => $general_settings['hit_ups_auto_company'], 'hit_ups_auto_mob_num' => $general_settings['hit_ups_auto_mob_num'], 'hit_ups_auto_email' => $general_settings['hit_ups_auto_email'], 'hit_ups_auto_address1' => $general_settings['hit_ups_auto_address1'], 'hit_ups_auto_address2' => $general_settings['hit_ups_auto_address2'], 'hit_ups_auto_city' => $general_settings['hit_ups_auto_city'], 'hit_ups_auto_state' => $general_settings['hit_ups_auto_state'], 'hit_ups_auto_zip' => $general_settings['hit_ups_auto_zip'], 'hit_ups_auto_country' => $general_settings['hit_ups_auto_country'], 'hit_ups_auto_gstin' => $general_settings['hit_ups_auto_gstin'], 'hit_ups_auto_con_rate' => $general_settings['hit_ups_auto_con_rate'], 'service_code' => $service_code, 'hit_ups_auto_label_email' => $general_settings['hit_ups_auto_label_email'], 'hit_ups_auto_ven_col_type' => isset($general_settings['hit_ups_auto_ven_col_type']) ? $general_settings['hit_ups_auto_ven_col_type'] : "", 'hit_ups_auto_ven_col_id' => isset($general_settings['hit_ups_auto_ven_col_id']) ? $general_settings['hit_ups_auto_ven_col_id'] : "", ); $vendor_settings = array(); if (isset($general_settings['hit_ups_auto_v_enable']) && $general_settings['hit_ups_auto_v_enable'] == 'yes' && isset($general_settings['hit_ups_auto_v_labels']) && $general_settings['hit_ups_auto_v_labels'] == 'yes') { // Multi Vendor Enabled foreach ($pack_products as $key => $value) { $product_id = $value['product_id']; if ($this->hpos_enabled) { $hpos_prod_data = wc_get_product($product_id); $ups_account = $hpos_prod_data->get_meta("hit_ups_auto_address"); } else { $ups_account = get_post_meta($product_id, 'hit_ups_auto_address', true); } if (empty($ups_account) || $ups_account == 'default') { $ups_account = 'default'; if (!isset($vendor_settings[$ups_account])) { $vendor_settings[$ups_account] = $custom_settings['default']; } $vendor_settings[$ups_account]['products'][] = $value; } if ($ups_account != 'default') { $user_account = get_post_meta($ups_account, 'hit_ups_auto_vendor_settings', true); $user_account = empty($user_account) ? array() : $user_account; if (!empty($user_account)) { if (!isset($vendor_settings[$ups_account])) { $vendor_settings[$ups_account] = $custom_settings['default']; if ($user_account['hit_ups_auto_site_id'] != '' && $user_account['hit_ups_auto_site_pwd'] != '' && $user_account['hit_ups_auto_acc_no'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_site_id'] = $user_account['hit_ups_auto_site_id']; if ($user_account['hit_ups_auto_site_pwd'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_site_pwd'] = $user_account['hit_ups_auto_site_pwd']; } if ($user_account['hit_ups_auto_acc_no'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_acc_no'] = $user_account['hit_ups_auto_acc_no']; } // $vendor_settings[$ups_account]['hit_ups_auto_access_key'] = !empty($user_account['hit_ups_auto_access_key']) ? $user_account['hit_ups_auto_access_key'] : ''; if ($user_account['hit_ups_auto_access_key'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_access_key'] = $user_account['hit_ups_auto_access_key']; } } // REST credentials $vendor_settings[$ups_account]['hit_ups_auto_rest_site_id'] = isset($user_account['hit_ups_auto_rest_site_id']) ? $user_account['hit_ups_auto_rest_site_id'] : ""; $vendor_settings[$ups_account]['hit_ups_auto_rest_site_pwd'] = isset($user_account['hit_ups_auto_rest_site_pwd']) ? $user_account['hit_ups_auto_rest_site_pwd'] : ""; $vendor_settings[$ups_account]['hit_ups_auto_rest_acc_no'] = isset($user_account['hit_ups_auto_rest_acc_no']) ? $user_account['hit_ups_auto_rest_acc_no'] : ""; $vendor_settings[$ups_account]['hit_ups_auto_rest_grant_type'] = isset($user_account['hit_ups_auto_rest_grant_type']) ? $user_account['hit_ups_auto_rest_grant_type'] : "client_credentials"; if ($user_account['hit_ups_auto_address1'] != '' && $user_account['hit_ups_auto_city'] != '' && $user_account['hit_ups_auto_state'] != '' && $user_account['hit_ups_auto_zip'] != '' && $user_account['hit_ups_auto_country'] != '' && $user_account['hit_ups_auto_shipper_name'] != '') { if ($user_account['hit_ups_auto_shipper_name'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_shipper_name'] = $user_account['hit_ups_auto_shipper_name']; } if ($user_account['hit_ups_auto_company'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_company'] = $user_account['hit_ups_auto_company']; } if ($user_account['hit_ups_auto_mob_num'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_mob_num'] = $user_account['hit_ups_auto_mob_num']; } if ($user_account['hit_ups_auto_email'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_email'] = $user_account['hit_ups_auto_email']; } if ($user_account['hit_ups_auto_address1'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_address1'] = $user_account['hit_ups_auto_address1']; } $vendor_settings[$ups_account]['hit_ups_auto_address2'] = $user_account['hit_ups_auto_address2']; if ($user_account['hit_ups_auto_city'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_city'] = $user_account['hit_ups_auto_city']; } if ($user_account['hit_ups_auto_state'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_state'] = $user_account['hit_ups_auto_state']; } if ($user_account['hit_ups_auto_zip'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_zip'] = $user_account['hit_ups_auto_zip']; } if ($user_account['hit_ups_auto_country'] != '') { $vendor_settings[$ups_account]['hit_ups_auto_country'] = $user_account['hit_ups_auto_country']; } $vendor_settings[$ups_account]['hit_ups_auto_gstin'] = $user_account['hit_ups_auto_gstin']; $vendor_settings[$ups_account]['hit_ups_auto_con_rate'] = $user_account['hit_ups_auto_con_rate']; if (isset($user_account['hit_ups_auto_ven_col_type']) && isset($user_account['hit_ups_auto_ven_col_id']) && !empty($user_account['hit_ups_auto_ven_col_id'])) { $vendor_settings[$ups_account]['hit_ups_auto_ven_col_type'] = $user_account['hit_ups_auto_ven_col_type']; $vendor_settings[$ups_account]['hit_ups_auto_ven_col_id'] = $user_account['hit_ups_auto_ven_col_id']; } } if (isset($general_settings['hit_ups_auto_v_email']) && $general_settings['hit_ups_auto_v_email'] == 'yes') { $user_dat = get_userdata($ups_account); $vendor_settings[$ups_account]['hit_ups_auto_label_email'] = $user_dat->data->user_email; } if ($order_data['shipping']['country'] != $vendor_settings[$ups_account]['hit_ups_auto_country']) { $vendor_settings[$ups_account]['service_code'] = empty($service_code) ? $user_account['hit_ups_auto_def_inter'] : $service_code; } else { $vendor_settings[$ups_account]['service_code'] = empty($service_code) ? $user_account['hit_ups_auto_def_dom'] : $service_code; } } unset($value['product_id']); $vendor_settings[$ups_account]['products'][] = $value; } } } } if (empty($vendor_settings)) { $custom_settings['default']['products'] = $pack_products; } else { $custom_settings = $vendor_settings; } if (!empty($general_settings) && isset($general_settings['hit_ups_auto_integration_key']) && isset($custom_settings[$create_shipment_for])) { $mode = 'live'; if (isset($general_settings['hit_ups_auto_test']) && $general_settings['hit_ups_auto_test'] == 'yes') { $mode = 'test'; } $execution = 'manual'; // if (isset($general_settings['hit_ups_auto_label_automation']) && $general_settings['hit_ups_auto_label_automation'] == 'yes') { // $execution = 'auto'; // } $pack_type = isset($_POST['hit_ups_auto_pack_type']) ? sanitize_text_field($_POST['hit_ups_auto_pack_type']) : '02'; $shipping_total = $order->get_shipping_total(); $data = array(); $data['integrated_key'] = $general_settings['hit_ups_auto_integration_key']; $data['order_id'] = $order_id; $data['exec_type'] = $execution; $data['mode'] = $mode; $data['carrier_type'] = "UPS"; $data['ship_price'] = $order_data['shipping_total']; $data['acc_rates'] = ($general_settings['hit_ups_auto_account_rates'] == 'yes') ? "Y" : "N"; $data['meta'] = array( "site_id" => $custom_settings[$create_shipment_for]['hit_ups_auto_site_id'], "password" => $custom_settings[$create_shipment_for]['hit_ups_auto_site_pwd'], "accountnum" => $custom_settings[$create_shipment_for]['hit_ups_auto_acc_no'], "site_acess" => $custom_settings[$create_shipment_for]['hit_ups_auto_access_key'], "api_type" => isset($general_settings['hit_ups_auto_api_type']) ? $general_settings['hit_ups_auto_api_type'] : "SOAP", "rest_api_key" => isset($custom_settings[$create_shipment_for]['hit_ups_auto_rest_site_id']) ? $custom_settings[$create_shipment_for]['hit_ups_auto_rest_site_id'] : "", "rest_secret_key" => isset($custom_settings[$create_shipment_for]['hit_ups_auto_rest_site_pwd']) ? $custom_settings[$create_shipment_for]['hit_ups_auto_rest_site_pwd'] : "", "rest_acc_no" => isset($custom_settings[$create_shipment_for]['hit_ups_auto_rest_acc_no']) ? $custom_settings[$create_shipment_for]['hit_ups_auto_rest_acc_no'] : "", "rest_grant_type" => isset($custom_settings[$create_shipment_for]['hit_ups_auto_rest_grant_type']) ? $custom_settings[$create_shipment_for]['hit_ups_auto_rest_grant_type'] : "", "s_company" => $order_shipping_company, "s_address1" => $order_shipping_address_1, "s_address2" => $order_shipping_address_2, "s_city" => $order_shipping_city, "s_state" => $order_shipping_state, "s_postal" => $order_shipping_postcode, "s_country" => $order_shipping_country, "s_name" => $order_shipping_phone, "s_phone" => $order_shipping_phone, "s_email" => $order_shipping_email, "dutiable" => $general_settings['hit_ups_auto_duty_payment'], "insurance" => $general_settings['hit_ups_auto_insure'], "pack_this" => "Y", "residential" => 'false', "drop_off_type" => "REGULAR_PICKUP", "packing_type" => $pack_type, "shipping_charge" => $shipping_total, "products" => $pack_products, //$custom_settings[$create_shipment_for]['products'], "pack_algorithm" => $general_settings['hit_ups_auto_packing_type'], "max_weight" => $general_settings['hit_ups_auto_max_weight'], "wight_dim_unit" => $general_settings['hit_ups_auto_weight_unit'], // "total_product_weg" => $total_weg, "plt" => ($general_settings['hit_ups_auto_ppt'] == 'yes') ? "Y" : "N", "simple_rate" => ($general_settings['hit_ups_auto_simple_rate'] == 'yes') ? "Y" : "N", "airway_bill" => ($general_settings['hit_ups_auto_aabill'] == 'yes') ? "Y" : "N", "sd" => ($general_settings['hit_ups_auto_sat'] == 'yes') ? "Y" : "N", "cod" => ($general_settings['hit_ups_auto_cod'] == 'yes') ? "Y" : "N", "service_code" => str_replace('ups_', '', $custom_settings[$create_shipment_for]['service_code']), "shipment_content" => $ship_content, "t_company" => $custom_settings[$create_shipment_for]['hit_ups_auto_company'], "t_address1" => $custom_settings[$create_shipment_for]['hit_ups_auto_address1'], "t_address2" => $custom_settings[$create_shipment_for]['hit_ups_auto_address2'], "t_city" => $custom_settings[$create_shipment_for]['hit_ups_auto_city'], "t_state" => $custom_settings[$create_shipment_for]['hit_ups_auto_state'], "t_postal" => $custom_settings[$create_shipment_for]['hit_ups_auto_zip'], "t_country" => $custom_settings[$create_shipment_for]['hit_ups_auto_country'], "gstin" => '', //$custom_settings[$create_shipment_for]['hit_ups_auto_gstin'], "t_name" => $custom_settings[$create_shipment_for]['hit_ups_auto_shipper_name'], "t_phone" => $custom_settings[$create_shipment_for]['hit_ups_auto_mob_num'], "t_email" => $custom_settings[$create_shipment_for]['hit_ups_auto_email'], "label_format" => "GIF", "sig_req" => "", "label_size" => $general_settings['hit_ups_auto_print_size'], "sent_email_to" => $custom_settings[$create_shipment_for]['hit_ups_auto_label_email'], "debug_log" => ($general_settings['hit_ups_auto_developer_rate'] == 'yes') ? 'Y' : 'N', "return" => "1", "add_shipping_invoice_flag" => ($general_settings['hit_ups_add_shipping_invoice'] == "yes") ? 'Y' : 'N', "del_con" => isset($general_settings['hit_ups_auto_del_con']) ? $general_settings['hit_ups_auto_del_con'] : "NONE", "label" => $create_shipment_for, "ref_no" => apply_filters('shipi_ref_no', '', $order_id) ); //RETURN SHIPMENT foreach ($data['meta']['products'] as $key => $value) { $data['meta']['products'][$key]['product_name'] = preg_replace('/[^\p{L}\s+\p{N}]/u', '', $value['product_name']); } // $return_ship_url = "http://localhost/hitshipo/label_api/create_shipment.php"; $return_ship_url = "https://app.myshipi.com/label_api/create_shipment.php"; $wp_pst = wp_remote_post($return_ship_url, array( 'body' => json_encode($data), 'timeout' => '60', 'redirection' => '10', 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'cookies' => array(), 'sslverify' => FALSE )); // $output = wp_remote_retrieve_body($wp_pst); $output = (is_array($wp_pst) && isset($wp_pst['body'])) ? (string)$wp_pst['body']: []; $output = json_decode($output, true); if ($output) { if (isset($output['status'])) { if (isset($output['status']) && $output['status'] != 'success') { update_option('hit_ups_auto_return_status_' . $order_id, $output['status']); } else if (isset($output['status']) && $output['status'] == 'success') { $output['user_id'] = $create_shipment_for; $result_arr = []; $val = get_option('hit_ups_auto_return_values_' . $order_id, array()); if(!empty($val)){ $result_arr = json_decode($val, true); } $result_arr[] = $output; update_option('hit_ups_auto_return_values_' . $order_id, json_encode($result_arr)); } } } else { update_option('hit_ups_auto_return_status_' . $order_id, 'Site not Connected with Shipi. Contact Shipi Team.'); } } } } } } } new hit_ups_auto_parent(); } // Add UPS column to WooCommerce Orders list add_filter('manage_edit-shop_order_columns', function ($columns) { $new_columns = []; foreach ($columns as $key => $column) { $new_columns[$key] = $column; // Insert UPS column after "order_total" if ($key === 'order_total') { $new_columns['ups_column'] = __('UPS', 'textdomain'); } } return $new_columns; }); add_action('manage_shop_order_posts_custom_column', function ($column, $post_id) { if ($column === 'ups_column') { $data = get_option('hit_ups_auto_values_' . $post_id); if (!empty($data)) { $data = json_decode($data, true); if (!empty($data) && isset($data[0]['tracking_num'])) { $tracking_num = esc_html($data[0]['tracking_num']); $track_url = 'https://track.myshipi.com/?no=' . urlencode($tracking_num) . '&track=1'; echo '' . $tracking_num . ''; } else { echo 'No Tracking'; } } else { echo 'No Tracking'; } } }, 10, 2);