(updated) - First you need to find the current day of the week using php function date()
this way:
$today= date('L');
Then we need to define the days for first email action and for 2nd email action storing this days in an array:
$days1 = array( 'monday', 'tuesday', 'Wednesday' );
$days2 = array( 'thursday', 'friday', 'saturday' );
Now we need to compare the current day $today
with $days1
and **$days
**2 to make an action:
if ( in_array( $today, $days1 ) ) {
// do something
} else if {
// do something else
} else {
exit; // do nothing
}
Now, for example, we can use the hook of this answer to your question combining the previous with it, this way:
add_action( 'woocommerce_payment_complete', 'order_completed' )
function order_completed( $order_id ) {
$today= date('L');
$days1 = array( 'monday', 'tuesday', 'Wednesday' );
$days2 = array( 'thursday', 'friday', 'saturday' );
$user_email = $current_user->user_email;
$to = sanitize_email( $user_email );
$headers = 'From: Your Name <your@email.com>' . "\r\n";
if ( in_array( $today, $days1 ) ) {
wp_mail($to, 'subject', 'This is custom email 1', $headers );
} elseif ( in_array( $today, $days2 ) ) {
wp_mail($to, 'subject', 'This is custom email 2', $headers );
} else {
exit; // do nothing
}
}
You can use on of this hooks too depending on your needs, and you can even combine them together:
add_action( 'woocommerce_order_status_pending', 'my_custom_action');
add_action( 'woocommerce_order_status_failed', 'my_custom_action');
add_action( 'woocommerce_order_status_on-hold', 'my_custom_action');
add_action( 'woocommerce_order_status_processing', 'my_custom_action');
add_action( 'woocommerce_order_status_completed', 'my_custom_action');
add_action( 'woocommerce_order_status_refunded', 'my_custom_action');
add_action( 'woocommerce_order_status_cancelled', 'my_custom_action');
add_action( 'woocommerce_payment_complete', 'my_custom_action' ); // Using this one
add_action( 'woocommerce_thankyou', 'my_custom_action' ); // this could be convenient too
function my_custom_function($order_id) {
// your code goes here
}
NOTE: All this code goes on function.php
file of your active child theme or theme