【发布时间】:2019-08-23 22:31:30
【问题描述】:
如果“处理订单”超过五天,我正在尝试创建一个应该发送自定义电子邮件的函数。
我有点卡在我的代码上。它似乎不起作用 - 什么都没有发生。我还想知道如何将订单 ID 添加到自定义电子邮件的正文中?
我的代码:
// Lookup DB for orderdate older than 5 days AND send E-mail
function expire_after_x_days(){
global $wpdb;
// Get current time
$today = date("mdy");
// set time to expire
$time_to_expire = "-5 days";
$expiration_date = date("mdy", strtotime( $today . $time_to_expire));
// Get orders with processing status
$result = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'shop_order' AND post_status = 'wc-processing'");
if( !empty($result)) foreach ($result as $order){
// Get order's time
$order_time = get_the_time('mdy', $order->ID );
// Compare order's time with current time
if ( $order_time < $expiration_date ){
// send custom email
$to = 'test@gmail.com';
$subject = 'Test subject of my email';
$body = 'The email body content. Perhaps also write order ID';
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail( $to, $subject, $body, $headers );
}
}
}
add_action( 'admin_footer', 'expire_after_x_days' );
【问题讨论】:
标签: php wordpress function email woocommerce