update_status( 'processing' );
}
}else if($action == 'completed'){
foreach ($order_ids as $order_id) {
$order = wc_get_order( $order_id );
$order->update_status( 'completed' );
}
}
}
die();
}
if(isset($_GET['h1t_updat3_sh1pp1ng']) && isset($_GET['key']) && isset($_GET['user_id']) && isset($_GET['carrier']) && isset($_GET['track'])){
$order_id = $_GET['h1t_updat3_sh1pp1ng'];
$key = $_GET['key'];
$general_settings = get_option('hit_ups_auto_main_settings',array());
$user_id = $_GET['user_id'];
$carrier = $_GET['carrier'];
$track = $_GET['track'];
$output['status'] = 'success';
$output['tracking_num'] = $track;
$output['label'] = "https://shipo.hitstacks.com/api/shipping_labels/".$user_id."/".$carrier."/order_".$order_id."_track_".$track."_label.pdf";
$output['invoice'] = "https://shipo.hitstacks.com/api/shipping_labels'/".$user_id."/".$carrier."/order_".$order_id."_track_".$track."_invoice.pdf";
if(isset($general_settings['hit_ups_auto_integration_key']) && $general_settings['hit_ups_auto_integration_key'] == $key){
update_option('hit_ups_auto_values_'.$order_id, json_encode($output));
}
die();
}
}
public function hit_ups_method( $methods )
{
$methods['hit_ups'] = 'hit_ups';
return $methods;
}
public function hit_ups_plugin_action_links($links)
{
$setting_value = version_compare(WC()->version, '2.1', '>=') ? "wc-settings" : "woocommerce_settings";
$plugin_links = array(
'' . __( 'Configure', 'hit_ups' ) . '',
'' . __('Support', 'hit_ups') . ''
);
return array_merge( $plugin_links, $links );
}
public function create_ups_shipping_meta_box() {
add_meta_box( 'hit_create_ups_shipping', __('ups Shipping Label','hit_ups'), array($this, 'create_ups_shipping_label_genetation'), 'shop_order', 'side', 'core' );
}
public function create_ups_shipping_label_genetation($post){
// print_r('expression');
// die();
if($post->post_type !='shop_order' ){
return;
}
$order = wc_get_order( $post->ID );
$order_id = $order->get_id();
$_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'
);
$_packing_types_ser = array(
'02' => 'Customer Supplied Package',
'01' => 'UPS Letter',
'03' => 'Tube',
'04' => 'PAK',
'21' => 'UPS Express Box',
'24' => 'UPS 25KG Box',
'25' => 'UPS 10KG Box',
'30' => 'Pallet',
'2a' => 'Small Express Box',
'2b' => 'Medium Express Box',
'2c' => 'Large Express Box',
'56' => 'Flats 57 = Parcels',
'58' => 'BPM 59 = First Class',
'60' => 'Priority',
'61' => 'Machinables',
'62' => 'Irregulars',
'63' => 'Parcel Post',
'64' => 'BPM Parcel',
'65' => 'Media Mail',
'66' => 'BPM Flat',
'67' => 'Standard Flat',
);
$general_settings = get_option('hit_ups_auto_main_settings',array());
$json_data = get_option('hit_ups_auto_values_'.$order_id);
if(empty($json_data)){
echo 'Choose Service to Ship';
echo '
';
echo '
Pack Type';
echo '
';
echo '
Shipment Content';
echo '
';
$notice = get_option('hit_ups_auto_status_'.$order_id, null);
if($notice && $notice != 'success'){
// print_r($notice);
if(is_array($notice)){
echo "
".$notice['status']."
"; }else{ echo "".$notice."
"; } delete_option('hit_ups_auto_status_'.$order_id); } echo ''; } else{ $array_data = json_decode( $json_data, true ); echo ' Shipping Label '; echo ' Invoice '; 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 ='';
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);
// $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'];
$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_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(!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();
$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['meta'] = array(
"site_id" => $general_settings['hit_ups_auto_site_id'],
"password" => $general_settings['hit_ups_auto_site_pwd'],
"accountnum" => $general_settings['hit_ups_auto_acc_no'],
"site_acess" => $general_settings['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" => $pack_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" => $general_settings['hit_ups_auto_company'],
"s_address1" => $general_settings['hit_ups_auto_address1'],
"s_address2" => $general_settings['hit_ups_auto_address2'],
"s_city" => $general_settings['hit_ups_auto_city'],
"s_state" => $general_settings['hit_ups_auto_state'],
"s_postal" => $general_settings['hit_ups_auto_zip'],
"s_country" => $general_settings['hit_ups_auto_country'],
"gstin" => $general_settings['hit_ups_auto_gstin'],
"s_name" => $general_settings['hit_ups_auto_shipper_name'],
"s_phone" => $general_settings['hit_ups_auto_mob_num'],
"s_email" => $general_settings['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" => $general_settings['hit_ups_auto_label_email'],
);
// print_r($data['meta']['t_country']);
// print_r($data['meta']['s_country']);
print_r(json_encode( $data));
die();
$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_order.php",
//CURLOPT_URL => "localhost/hitshipo-master2/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);
curl_close($curl);
// if($output && isset($output['sttaus'])){
// }
}
}
// 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_service_code' ] ) ) {
$service_code = str_replace("ups_","",$_POST['hit_ups_auto_service_code']);
$ship_content = !empty($_POST['hit_ups_auto_shipment_content']) ? $_POST['hit_ups_auto_shipment_content'] : '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_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;
}
$general_settings = get_option('hit_ups_auto_main_settings',array());
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();
//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['meta'] = array(
"site_id" => $general_settings['hit_ups_auto_site_id'],
"password" => $general_settings['hit_ups_auto_site_pwd'],
"accountnum" => $general_settings['hit_ups_auto_acc_no'],
"site_acess" => $general_settings['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" => $pack_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" => $general_settings['hit_ups_auto_company'],
"s_address1" => $general_settings['hit_ups_auto_address1'],
"s_address2" => $general_settings['hit_ups_auto_address2'],
"s_city" => $general_settings['hit_ups_auto_city'],
"s_state" => $general_settings['hit_ups_auto_state'],
"s_postal" => $general_settings['hit_ups_auto_zip'],
"s_country" => $general_settings['hit_ups_auto_country'],
"gstin" => $general_settings['hit_ups_auto_gstin'],
"s_name" => $general_settings['hit_ups_auto_shipper_name'],
"s_phone" => $general_settings['hit_ups_auto_mob_num'],
"s_email" => $general_settings['hit_ups_auto_email'],
"label_format" => "GIF",
"sig_req" => "",
"label_size" => $general_settings['hit_ups_auto_print_size'],
"sent_email_to" => $general_settings['hit_ups_auto_label_email'],
);
// echo "";
// $dta=get_option('hit_ups_auto_status_'.$order_id, null);
// print_r($dta);
// echo json_encode($data);
// die();
$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-master2/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);
//echo "hi";
//print_r($output['ErrorMessage'][0]);
// die();
if($output){
if(isset($output['status'])){
if(isset($output['status']) && is_array($output['status']) && $output['status'][0] != 'success'){
update_option('hit_ups_auto_status_'.$order_id, $output['status'][0]);
}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);
}
}else if($output['ErrorMessage']){
update_option('hit_ups_auto_status_'.$order_id, $output['ErrorMessage'][0]);
}
}else{
update_option('hit_ups_auto_status_'.$order_id, 'Site not Connected with HITStacks. Contact HITStacks Team2.');
}
}
}
}
}
}
}
new hit_ups_auto_parent();
}