Hi,
Sorry for not getting back to you sooner.
Do you mean you want to run this once, i.e., go through all your currently existing users and send an email if the user has two or more orders?
If that’s the case, please add this PHP snippet to your site:
/**
* Sends custom emails to the users.
*
* @see https://example.com/wp-admin/?my_wpfactory_send_user_emails
*/
add_action( 'admin_init', function () {
if (
isset( $_GET['my_wpfactory_send_user_emails'] ) &&
current_user_can( 'manage_woocommerce' ) &&
function_exists( 'alg_wc_ce_send_email' )
) {
// Custom vars
$custom_email_id = 1; // Custom email #1
$min_order_count = 2;
// Set up user emails
add_filter( 'alg_wc_custom_emails_is_user_email', '__return_true' );
// Users loop
$users = get_users( array( 'role__in' => array( 'customer' ) ) );
foreach ( $users as $user ) {
if (
( $customer = new WC_Customer( $user->ID ) ) &&
$customer->get_order_count() >= $min_order_count
) {
alg_wc_ce_send_email( $custom_email_id, $user->ID );
}
}
// The end
die();
}
} );
After that, you can run the snippet with this URL:
https://example.com/wp-admin/?my_wpfactory_send_user_emails
The snippet will send the “Custom email #1” (you can change that by updating the $custom_email_id
value in the snippet) to each user with two or more orders (see the $min_order_count
).
In the email settings (in “WooCommerce > Settings > Emails > Custom email #X”), leave the “Recipients” field empty – the plugin will automatically use the user’s email.
Also, you can use our [user_prop]
shortcode in the content, e.g.:
Hi, [user_prop key="display_name"],
Please give it a try and let me know what you think.