Reputation: 1
I'm very new to coding and i want to make a function that can send a email reminder one day before delivery date on completed orders in WooCommerce 3.1.1.
I'm using the plugin WooCommerce Delivery Slots and got the information about delivery date here:http://docs.iconicwp.com/article/53-get-the-delivery-date-for-an-order
I don't know how to proceed for making this function work.
add_action("init", "send_reminder_note");
function send_reminder_note($order_id) {
$order = wc_get_order( $order_id );
foreach ( $order_id as $id ) {
//Get all order data
$order_data = $order->get_data(); // The Order data
$order_id = $order_data['id'];
$order_parent_id = $order_data['parent_id'];
$order_status = $order_data['status'];
$order_billing_email = $order_data['billing']['email'];
//Get one day before delivery date
$date = get_post_meta( $order_id, 'jckwds_date', true ); // delivery date
$date_temp = get_post_meta( $order_id, 'jckwds_date', true );
$date = date("Ymd", strtotime("-1 days"));
//Send emils if orders is completed and one day before delivery date
if($order_status == 'completed' ) {
if($date_temp >= $date){
$to = $order_billing_email;
$subject = 'Reminder your package will be sent tomorrow';
$body = 'your order will be sent tommorow';
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail( $to, $subject, $body, $headers );
}
}
}
}
Upvotes: 0
Views: 617
Reputation: 795
I am not sure to have understood your question.
Given your jckwds_date
field in your orders table is the delivery date,
I'd suggest you to set a cron (https://en.wikipedia.org/wiki/Cron) and run it once a day. This cron will run a PHP file with a function similar to the one you wrote but with this flow:
jckwds_date
== date of tomorrowI hope this helps.
Upvotes: 0