我正试图在产品页面上添加估计交货。该插件应具有以下功能:-交货时间为4个工作日-在航运和交货的周末-截止时间为下午1:00(13:00)
在function.php中的代码如下:
add_action('woocommerce_before_add_to_cart_form', 'display_delivery_estimate');
function display_delivery_estimate() {
$now = current_time('timestamp');
$cutoff_hour = 13;
$working_days = 4;
$delivery_date = "";
$shipping_date = $now;
if (date('H', $now) >= $cutoff_hour) {
$shipping_date = strtotime('+2 day', $shipping_date);
} else {
$shipping_date = strtotime('+1 day', $shipping_date);
}
$delivery_date=$shipping_date + 2;
if (date('N', $delivery_date) >= 6) {
$delivery_date = strtotime('+2 days', $delivery_date);
}
else {
$delivery_date = strtotime('+4 days', $delivery_date);
}
echo '<p>Consegna stimata tra ' . date_i18n('l, j F', $shipping_date) . ' - ' . date_i18n('l, j F', $delivery_date) . '</p>';
}
字符串
问题是代码似乎不起作用。在预期的日子里仍然有工作日。我如何解决这个问题?谢谢
1条答案
按热度按时间2nc8po8w1#
代码中的主要问题是检查周末并跳到下周。
字符串