$userId = $_GET[‘userId’];
$preorder_status = get_post_meta( $order_id, ‘pre_order_status’, true );
if(!isset($preorder_status) || $preorder_status != 1)
{
$order = new WC_Order($order_id );
$kerry_fast = 0 ;
foreach ( $order->get_order_item_totals() as $key => $total )
{
if(strpos($total[‘value’], ‘ด่วน’) !== false)
{
$kerry_fast = 1;
}
if(strpos($total[‘value’], ‘Kerry’) !== false)
{
$kerry_fast = 1;
}
if(strpos($total[‘value’], ‘kerry’) !== false)
{
$kerry_fast = 1;
}
}
$thisfri = date(‘Y-m-d’,strtotime(‘this friday’)); //2014-07-08
$thistue = date(‘Y-m-d’,strtotime(‘this tuesday’)); //2014-07-09
$thaiweek=array(“วันอาทิตย์”,”วันจันทร์”,”วันอังคาร”,”วันพุธ”,”วันพฤหัส”,”วันศุกร์”,”วันเสาร์”);
$thaimonth=array(“มกราคม”,”กุมภาพันธ์”,”มีนาคม”,”เมษายน”,”พฤษภาคม”,”มิถุนายน”,”กรกฎาคม”,”สิงหาคม”,”กันยายน”,”ตุลาคม”,”พฤศจิกายน”,”ธันวาคม”);
$shipDate = ”;
if($thisfri > $thistue)
{
$shipDate = $thaiweek[date(‘w’,strtotime(‘this tuesday’))];
$shipDate = $shipDate.”ที่ “.date(‘j’,strtotime(‘this tuesday’)).” “;
$shipDate = $shipDate.$thaimonth[date(‘m’,strtotime(‘this tuesday’))-1];
//$shipDate = $shipDate.” พ.ศ. “.date(” Y “,strtotime(‘this tuesday’))+543;
}
else
{
$shipDate = $thaiweek[date(‘w’,strtotime(‘this friday’))];
$shipDate = $shipDate.”ที่ “.date(‘j’,strtotime(‘this friday’)).” “;
$shipDate = $shipDate.$thaimonth[date(‘m’,strtotime(‘this friday’))-1];
}
//check if wed or friday
date_default_timezone_set(‘Asia/Bangkok’);
$dayofweek = date(“l”);
if($dayofweek == ‘Tuesday’ || $dayofweek == ‘Friday’)
{
$pm = date(“a”);
if($pm == ‘pm’)
{
if((int)date(“h”) >= 9 && (int)date(“h”) < 12)
{
if($thisfri > $thistue)
{
$shipDate = $thaiweek[date(‘w’,strtotime(‘this friday’))];
$shipDate = $shipDate.”ที่ “.date(‘j’,strtotime(‘this friday’)).” “;
$shipDate = $shipDate.$thaimonth[date(‘m’,strtotime(‘this friday’))-1];
}
else
{
$shipDate = $thaiweek[date(‘w’,strtotime(‘this tuesday’))];
$shipDate = $shipDate.”ที่ “.date(‘j’,strtotime(‘this tuesday’)).” “;
$shipDate = $shipDate.$thaimonth[date(‘m’,strtotime(‘this tuesday’))-1];
}
}
}
}
if($dayofweek == ‘friday’ || $dayofweek == ‘tuesday’)
{
if($thisfri > $thistue)
{
$shipDate = $thaiweek[date(‘w’,strtotime(‘this friday’))];
$shipDate = $shipDate.”ที่ “.date(‘j’,strtotime(‘this friday’)).” “;
$shipDate = $shipDate.$thaimonth[date(‘m’,strtotime(‘this friday’))-1];
}
else
{
$shipDate = $thaiweek[date(‘w’,strtotime(‘this tuesday’))];
$shipDate = $shipDate.”ที่ “.date(‘j’,strtotime(‘this tuesday’)).” “;
$shipDate = $shipDate.$thaimonth[date(‘m’,strtotime(‘this tuesday’))-1];
}
}
if($kerry_fast == 0)
{
$shipDate = ‘วันอังคารที่ 10 มีนาคม’ ;
$note = ‘รอบจัดส่งถัดไป “‘.$shipDate.'” นี้นะคะ’;
$url = ‘https://feather-potato.glitch.me/notify-submit-confirm-address’;
$data = [
‘userId’ => $userId ,
‘messageTxt’ => $note
];
$post = json_encode($data);
$headers = array(‘Content-Type: application/json’);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
if($order_id == 197943)
{
$note = ‘คุณได้รับ 80 coin รายละเอียดเพิ่มเติม https://katasia-worldshop.com/phone-login/index3.html’;
//$note = ‘รอบจัดส่งถัดไป “‘.$shipDate.'” นี้นะคะ’;
$url = ‘https://feather-potato.glitch.me/notify-submit-confirm-address’;
$data = [
‘userId’ => $userId ,
‘messageTxt’ => $note
];
$post = json_encode($data);
$headers = array(‘Content-Type: application/json’);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
}
}
}
else
{
$note = ‘รายการของลูกค้าเป็น “รายการจอง” ก่อนการจัดส่งสินค้า ทางเราจะแจ้งไปนะคะ’;
$url = ‘https://feather-potato.glitch.me/notify-submit-confirm-address’;
$data = [
‘userId’ => $userId ,
‘messageTxt’ => $note
];
$post = json_encode($data);
$headers = array(‘Content-Type: application/json’);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
}
[/insert_php]