Custom email for existing users

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #142517
    Joe m
    Participant

    Hi, Can we set up a thank you email which needs to trigger for existing users who are ordering on 2 or more than times.?

    #142557
    Moshtafizur
    Moderator
    Plugin Support

    Hi there,

    Thanks for reaching out.

    We are sorry to let you know that at this moment it is not possible to achieve with our plugin. But I have passed your request to our development team. They will get back to you as soon as possible.

    Kind regards.

    #142848
    Tom Anbinder
    Moderator
    Plugin Support

    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.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.