use order update meta
This commit is contained in:
@@ -58,10 +58,10 @@ class Wiaas_Order {
|
||||
'url' => ''
|
||||
);
|
||||
|
||||
//not working
|
||||
//$order = wc_get_order($order_id);
|
||||
//$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||
return update_post_meta($order_id, '_wiaas_suppliers', $suppliers);
|
||||
$order = wc_get_order($order_id);
|
||||
$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||
$order->save_meta_data();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,10 +75,11 @@ class Wiaas_Order {
|
||||
$suppliers[$key]['tracking_info'][$tracking_index]['number'] = $tracking_num;
|
||||
$suppliers[$key]['tracking_info'][$tracking_index]['url'] = $tracking_url;
|
||||
|
||||
//not working
|
||||
//$order = wc_get_order($order_id);
|
||||
//$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||
return update_post_meta($order_id, '_wiaas_suppliers', $suppliers);
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||
$order->save_meta_data();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,10 +92,10 @@ class Wiaas_Order {
|
||||
if ($supplier['id'] === $supplier_id){
|
||||
unset($suppliers[$key]['tracking_info'][$tracking_index]);
|
||||
|
||||
//not working
|
||||
//$order = wc_get_order($order_id);
|
||||
//$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||
return update_post_meta($order_id, '_wiaas_suppliers', $suppliers);
|
||||
$order = wc_get_order($order_id);
|
||||
$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||
$order->save_meta_data();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,42 +104,51 @@ class Wiaas_Order {
|
||||
|
||||
public static function save_estimated_date($order_id, $supplier_id, $date){
|
||||
$suppliers = self::get_suppliers($order_id);
|
||||
$result = false;
|
||||
|
||||
$updated = false;
|
||||
foreach($suppliers as $key => $supplier){
|
||||
if ($supplier['id'] === $supplier_id){
|
||||
$suppliers[$key]['estimated_date'] = $date;
|
||||
$updated = true;
|
||||
}
|
||||
}
|
||||
|
||||
$result = update_post_meta($order_id, '_wiaas_suppliers', $suppliers);
|
||||
self::_update_max_and_earliest_dates($order_id);
|
||||
//Not working
|
||||
//$order = wc_get_order($order_id);
|
||||
//$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||
|
||||
return $result;
|
||||
if (!$updated){
|
||||
return false;
|
||||
}
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||
self::_update_max_and_earliest_dates($order, $suppliers);
|
||||
|
||||
$order->save_meta_data();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function save_confirmed_date($order_id, $supplier_id, $date){
|
||||
$suppliers = self::get_suppliers($order_id);
|
||||
$result = false;
|
||||
$updated = false;
|
||||
foreach($suppliers as $key => $supplier){
|
||||
if ($supplier['id'] === $supplier_id){
|
||||
$suppliers[$key]['confirmed_date'] = $date;
|
||||
$updated = true;
|
||||
if (!$suppliers[$key]['estimated_date']){
|
||||
$suppliers[$key]['estimated_date'] = $date;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$updated){
|
||||
return false;
|
||||
}
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$result = update_post_meta($order_id, '_wiaas_suppliers', $suppliers);
|
||||
self::_update_max_and_earliest_dates($order_id);
|
||||
//Not working
|
||||
//$order = wc_get_order($order_id);
|
||||
//$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||
return $result;
|
||||
$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||
self::_update_max_and_earliest_dates($order, $suppliers);
|
||||
|
||||
$order->save_meta_data();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function get_global_estimated_date($order_id){
|
||||
@@ -342,9 +352,7 @@ class Wiaas_Order {
|
||||
* PRIVATE
|
||||
*/
|
||||
|
||||
private static function _update_max_and_earliest_dates($order_id){
|
||||
$suppliers = self::get_suppliers($order_id);
|
||||
|
||||
private static function _update_max_and_earliest_dates($order, $suppliers){
|
||||
$max_estimated_date = 0;
|
||||
$max_confirmed_date = 0;
|
||||
$earliest_installation_date = 0;
|
||||
@@ -389,13 +397,12 @@ class Wiaas_Order {
|
||||
}
|
||||
|
||||
if (!$no_earliest){
|
||||
$earliest_installation_date = strtotime('+' . self::get_additional_days_prior_installation($order_id) . ' days', $earliest_installation_date);
|
||||
$earliest_installation_date = strtotime('+' . self::get_additional_days_prior_installation($order->id) . ' days', $earliest_installation_date);
|
||||
}
|
||||
|
||||
update_post_meta($order_id, '_wiaas_final_confirmed_delivery_date', $max_confirmed_date);
|
||||
update_post_meta($order_id, '_wiaas_final_estimated_delivery_date', $max_estimated_date);
|
||||
update_post_meta($order_id, '_wiaas_earliest_installation_date', $earliest_installation_date);
|
||||
|
||||
$order->update_meta_data('_wiaas_final_confirmed_delivery_date', $max_confirmed_date);
|
||||
$order->update_meta_data('_wiaas_final_estimated_delivery_date', $max_estimated_date);
|
||||
$order->update_meta_data('_wiaas_earliest_installation_date', $earliest_installation_date);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user