【发布时间】:2023-03-23 23:17:02
【问题描述】:
我在午夜使用服务器 cron 作业来安排 WP 事件,以向客户发送有关其过期产品的更新。无论我写什么,时间都会转换为我的 UTC+5 时区。
PHP 代码:
function register_daily_expired_products_event() {
if (!wp_next_scheduled('send_emails')) {
// Schedule daily expired products event
wp_schedule_event(strtotime('today midnight'), 'daily', 'ptmp_notify_customers');
}
}
add_action('init', 'register_daily_expired_products_event');
function ptmp_send_product_expiry_emails() {
// Custom code
}
// Notify customers with their expired products
add_action('ptmp_notify_customers', 'ptmp_send_product_expiry_emails');
使用 WP Crontrol 插件测试的 cron 作业事件,根据我的时区 (UTC+5) 显示 +5 小时。例如
时间应该是: 2017-07-08 00:00:00
但实际上: 2017-07-08 05:00:00(加5小时)
服务器 cron 作业在 12:00 AM 准确运行,但在后端,该事件还有 5 个小时以上,尚未准备好执行。因此,即使客户当天的产品已过期,也不会发送任何电子邮件。任何帮助将不胜感激。 谢谢!
【问题讨论】: