Basic cronjob
<?php
add_action( 'cron_check_order_status', 'check_order_statuses' );
function activate_cron() {
if (! wp_next_scheduled ( 'cron_check_order_status' )) {
wp_schedule_event( time(), 'daily', 'cron_check_order_status' );
}
}
function deactivate_cron() {
wp_clear_scheduled_hook('cron_check_order_status');
}
add_action('wp', 'deactivate_cron');
function isWeekend($date) {
return (date('N', strtotime($date)) >= 6);
}
function check_order_statuses() {
if(!isWeekend(date('Y-m-d'))) {
global $wpdb;
$weekback = date('Y-m-d', time() + (60 * 60 * 24 * -7));
$querystr = "
SELECT * FROM $wpdb->posts
WHERE $wpdb->posts.post_type = 'shop_order'
AND $wpdb->posts.post_status = 'wc-labels-send'
AND $wpdb->posts.post_date <= '{$weekback} 23:59:59'
";
$result = $wpdb->get_results($querystr);
if($result[0]) {
foreach($result as $order) {
$myorder = new WC_Order($order->ID);
$to = $myorder->billing_email;
$subject = (get_field('title','option') ? get_field('title','option') : 'Herinnering email labels');
$body = 'He '.$myorder->billing_first_name .', <br><br>'.
(get_field('text','option') ? get_field('text','option') : 'Dit is een herinnering mail omdat u nog niet de order labels heeft bevestigd. Dit kunt u doen via onderstaande link: <br><br>').
'<a href="'.get_permalink( get_option('woocommerce_myaccount_page_id') ).'">Mijn account</a>';
$headers = array('Content-Type: text/html; charset=UTF-8');
$headers[] = 'From: '.get_bloginfo( 'name', 'display' ).' <'.get_bloginfo( 'admin_email', 'display' ).'>';
$headers[] = 'Cc: '.get_bloginfo( 'admin_email', 'display' );
wp_mail( $to, $subject, $body, $headers );
}
}
}
}