Opencart的交货日期

时间:2014-08-12 10:19:05

标签: php datetime opencart

我在opencart上有一个网站,我在第4步(交付方式)上有这个;

Interlink Express 24 Courier

  • Interlink Express - 获取:8月13日星期三

我已经有了一个代码,但它似乎没有用,在星期六它似乎仍然显示星期日作为交付日期。

<?php
// Text
$_['text_title'] = 'Interlink Express 24 Courier';

$datetime = new DateTime('tomorrow');
if ($datetime->format('l') == 'Sunday') $datetime = new DateTime('tomorrow + 1 day');


$_['text_description'] = 'Interlink Express - Get it on: ' . $datetime->format('l, jS \of F ');
$_['text_weight'] = 'Weight:';
$_['text_insurance'] = 'Insured upto:';
$_['text_time'] = 'Estimated Time: Within 24 Hours'; 
?>

此外,是否可以在一定时间(下午5:00)之后显示下一个日期?

因此,在星期一的5:01,它显示的是星期三而不是星期二。

1 个答案:

答案 0 :(得分:1)

更改这两行

$datetime = new DateTime('tomorrow');
if ($datetime->format('l') == 'Sunday') $datetime = new DateTime('tomorrow + 1 day');

进入这些:

$now = new DateTime(); // uses actual date and time
if ($now->format('l') == 'Saturday') {
    // it is Saturday, delivery will be on Tuesday
    $datetime = new DateTime('tomorrow + 2 day');
} elseif ($now->format('l') == 'Sunday' || in_array($now->format('l'), array('Monday', 'Tuesday', 'Wednesday')) && ((int) $now->format('H')) > 17) {
    // it is Sunday - delivery will be on Tuesday
    // or it is working day Mon..Wed after 5 p.m. - delivery will be on second working day
    $datetime = new DateTime('tomorrow + 1 day');
} elseif (in_array($now->format('l'), array('Thursday', 'Friday')) && ((int) $now->format('H')) > 17) {
    // it is Thursday after 5 p.m. - delivery will be on next Monday
    // or it is Friday after 5 p.m. - delivery will be on next Tuesday
    $datetime = new DateTime('tomorrow + 3 day');
} else {
    $datetime = new DateTime('tomorrow');
}

这应该可以解决问题。