__( '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) { echo '
';print_r($events);die(); $to_disp .= 'Package Status: '.$last_event_status.'Package '.$trk_count.' of '.$tot_trk_count.' Tracking No: '.$trk_no.''; }else { $to_disp .= ''; foreach ($events as $key => $value) { $event_status = isset($value['Status']['StatusType']['Description']) ? $value['Status']['StatusType']['Description'] : '-'; $event_loc = isset($value['ActivityLocation']['Address']['City']) ? $value['ActivityLocation']['Address']['City'] : '-'; $event_country = isset($value['ActivityLocation']['Address']['CountryCode']) ? $value['ActivityLocation']['Address']['CountryCode'] : '-'; $event_time = isset($value['GMTTime']) ? date('h:i - A', strtotime($value['GMTTime'])) : '-'; $event_date = isset($value['GMTDate']) ? date('M d Y', strtotime($value['GMTDate'])) : '-'; $to_disp .= '
- '; } $to_disp .= '
'.$event_date.'
'.$event_time.'
'; if (isset($value['Status']['StatusType']['Code']) && $value['Status']['StatusType']['Code'] == "D") { $to_disp .= ''; }else { $to_disp .= '
'; } $to_disp .= ''.$event_status.'
'.$event_loc.' , '.$event_country.'
Sorry! No data found for this package...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
".$notice."
"; 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'){ echo '";
// print_r($custom_settings);
}else{
$user = get_user_by( 'id', $ukey );
echo '
Account: '.$user->display_name.'';
echo '
';
echo '
Pack Type';
echo '
';
echo '
Shipment Content';
echo '
';
echo '
';
}
}
//...................
}
public function hit_wc_checkout_order_processed($order_id){
// echo "hiiiiiiiii";
// echo "";
$_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'
);
//print_r($order);
// die();
$post = get_post($order_id);
if($post->post_type !='shop_order' ){
return;
}
$ship_content = !empty($_POST['hit_ups_auto_shipment_content']) ? $_POST['hit_ups_auto_shipment_content'] : 'Shipment Content';
$order = wc_get_order( $order_id );
//print_r($order);
$service_code = $multi_ven = '';
foreach( $order->get_shipping_methods() as $item_id => $item ){
$service_nme = $item->get_name();
//print_r($service_nme);
$select_code = array_search($service_nme, $_ups_carriers);
$service_code = str_replace("ups_","",$select_code);
//print_r($service_code);
$multi_ven = $item->get_meta('a2z_multi_ven');
// $service_code = $item->get_meta('hit_ups_auto_service');
// print_r($item);
}
if(empty($service_code)){
return;
}
$order_data = $order->get_data();
//print_r($order_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'];
$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'];
$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_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'],
);
$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'] = round(wc_get_dimension($getproduct->get_width(),$mod_dim_unit,$woo_dim_unit));
//print_r($product['price']);
$product['height'] = round(wc_get_dimension($getproduct->get_height(),$mod_dim_unit,$woo_dim_unit));
//print_r($product['height']);
$product['depth'] = round(wc_get_dimension($getproduct->get_length(),$mod_dim_unit,$woo_dim_unit));
$product['weight'] = (float)round(wc_get_weight($getproduct->get_weight(),$mod_weg_unit,$woo_weg_unit),2);
$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'];
$ups_account = get_post_meta($product_id,'hit_ups_auto_address', true);
if(empty($ups_account) || $ups_account == 'default'){
$ups_account = 'default';
$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_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($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'];
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 = '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'])?$_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['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'],
"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'],
// "total_product_weg" => $total_weg,
"plt" => ($general_settings['hit_ups_auto_ppt'] == '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'],
"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'],
"label" => $key,
);
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));
$curl = curl_init();
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen(json_encode($data)))
);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://shipo.hitstacks.com/api/ups_order.php",
// CURLOPT_URL => "localhost/hitshipo/api/ups_order.php",
CURLOPT_RETURNTRANSFER => false,
CURLOPT_POST => true,
CURLOPT_USERAGENT => 'api',
CURLOPT_FORBID_REUSE => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_HEADER => false,
CURLOPT_TIMEOUT => 30,
CURLOPT_CONNECTTIMEOUT => 1,
CURLOPT_DNS_CACHE_TIMEOUT => 10,
CURLOPT_FRESH_CONNECT => true,
CURLOPT_CUSTOMREQUEST => 'POST',
));
curl_exec($curl);
// $output = utf8_encode(curl_exec($curl));
curl_close($curl);
// if($output && isset($output['sttaus'])){
// print_r(json_decode($output));
// }
}
// die();
}
}
// Save the data of the Meta field
public function hit_create_ups_shipping( $order_id ) {
$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 = $_POST['hit_ups_auto_create_label'];
// print_r($create_shipment_for);
// die();
$service_code = str_replace("ups_","",$_POST['hit_ups_auto_service_code_'.$create_shipment_for]);
// print_r($service_code);
// die();
$ship_content = !empty($_POST['hit_ups_auto_shipment_content_'.$create_shipment_for]) ? $_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'];
$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'] = round(wc_get_dimension($getproduct->get_width(),$mod_dim_unit,$woo_dim_unit));
$product['height'] = round(wc_get_dimension($getproduct->get_height(),$mod_dim_unit,$woo_dim_unit));
$product['depth'] = round(wc_get_dimension($getproduct->get_length(),$mod_dim_unit,$woo_dim_unit));
$product['weight'] = (float)round(wc_get_weight($getproduct->get_weight(),$mod_weg_unit,$woo_weg_unit),2);
$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_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'],
);
$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'];
$ups_account = get_post_meta($product_id,'hit_ups_auto_address', true);
if(empty($ups_account) || $ups_account == 'default'){
$ups_account = 'default';
$vendor_settings[$ups_account] = $custom_settings['default'];
$vendor_settings[$ups_account]['products'][] = $value;
}
// print_r($ups_account);
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_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($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;
}
}
}
}
// print_r($vendor_settings);
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'])?$_POST['hit_ups_auto_pack_type']:'02';
$shipping_total = $order->get_shipping_total();
//print_r($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['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'],
"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'],
// "total_product_weg" => $total_weg,
"plt" => ($general_settings['hit_ups_auto_ppt'] == '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'],
"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'],
);
foreach($data['meta']['products'] as $key=>$value){
$data['meta']['products'][$key]['product_name'] = preg_replace('/[^\p{L}\s+\p{N}]/u', '',$value['product_name']);
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://shipo.hitstacks.com/api/ups_manual.php",
// CURLOPT_URL => "localhost/hitshipo/api/ups_manual.php",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_HEADER => false,
CURLOPT_TIMEOUT => 60,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
));
$output = json_decode(curl_exec($curl),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']) == 'success'){
// update_option('hit_ups_auto_values_'.$order_id, json_encode($output));
// update_option('hit_ups_auto_status_'.$order_id, $output);
$output['user_id'] = $create_shipment_for;
$result_arr = json_decode(get_option('hit_ups_auto_values_'.$order_id, array()));
$result_arr[] = $output;
update_option('hit_ups_auto_values_'.$order_id, json_encode($result_arr));
}
}
}else{
update_option('hit_ups_auto_status_'.$order_id, 'Site not Connected with HITStacks. Contact HITStacks Team.');
}
}
}
}
}
}
}
new hit_ups_auto_parent();
}