2 回答
TA贡献1862条经验 获得超6个赞
这是检查是否有更多(或更少)超过24小时,因为一个订单已创建,使用传递的方式WC_DateTime,并DateTime在订购方法创建日期时间:
$order = wc_get_order($order_id); // Get an instance of the WC_Order Object
$date_created_dt = $order->get_date_created(); // Get order date created WC_DateTime Object
$timezone = $date_created_dt->getTimezone(); // Get the timezone
$date_created_ts = $date_created_dt->getTimestamp(); // Get the timestamp in seconds
$now_dt = new WC_DateTime(); // Get current WC_DateTime object instance
$now_dt->setTimezone( $timezone ); // Set the same time zone
$now_ts = $now_dt->getTimestamp(); // Get the current timestamp in seconds
$twenty_four_hours = 24 * 60 * 60; // 24hours in seconds
$diff_in_seconds = $now_ts - $date_created_ts; // Get the difference (in seconds)
// Output
if ( $diff_in_seconds < $twenty_four_hours ) {
echo '<p>Order created LESS than 24 hours ago</p>';
} elseif ( $diff_in_seconds = $twenty_four_hours ) {
echo '<p>Order created 24 hours ago</p>';
} else {
echo '<p>Order created MORE than 24 hours ago</p>';
}
TA贡献1773条经验 获得超3个赞
要检查订单是否在 24 小时前创建,您可以从订单时间戳中减去当前时间戳,然后检查该差异是否大于 DAY_IN_SECONDS。
time() - $order->get_date_created()->getTimestamp() > DAY_IN_SECONDS
- 2 回答
- 0 关注
- 122 浏览
添加回答
举报