1 回答
TA贡献1898条经验 获得超8个赞
使用l, \t\h\e jS \of F,格式化字符串,我可以使用您的代码获得正确的输出。我还做了一些更改,例如替换"day after tomorrow"为"+2 days"和使用的sprintf()功能:
add_action( 'woocommerce_before_single_product_summary', 'product_delivery_message' );
add_action( 'woocommerce_before_shop_loop', 'product_delivery_message' );
add_action( 'woocommerce_before_cart', 'product_delivery_message' );
add_action( 'woocommerce_before_checkout_form', 'product_delivery_message' );
function product_delivery_message() {
date_default_timezone_set( 'Europe/Paris' );
$date_format = __('l, \t\h\e jS \of F,', 'woocommerce');
// 1. Delivery cut-off for friday and weekend
if ( date_i18n('N') >= 5 ) {
$delivery_day = date_i18n( $date_format, strtotime( "next wednesday" ) );
$order_before = __('Monday', 'woocommerce');
}
// 2. From monday to thursday before XX (currently set to 18 = 6PM), delivery will be on next week tuesday
elseif ( date_i18n('H') >= 18 ) {
$delivery_day = date_i18n( $date_format, strtotime( "+2 days" ) );
$order_before = __('tomorrow', 'woocommerce');
}
// 3. From monday to thursday within the cut-off time, delivery will be next day (tomorrow)
else {
$delivery_day = date_i18n( $date_format, strtotime( "+1 day" ) );
$order_before = __('today', 'woocommerce');
}
$message = sprintf(
__("Orders made before 6PM %s will be delivered on %s or the day after at the latest.", "woocommerce"),
$order_before, $delivery_day
);
echo '<div class="product-delivery-message" style="clear:both">' . $message . '</div>';
}
代码位于活动子主题(或活动主题)的functions.php 文件中。经过测试并有效。
- 1 回答
- 0 关注
- 114 浏览
添加回答
举报