I’ve created a sign up page for new customers to create an account.

This is working fine but I would like to hook into WooCommerce customer_new_account inside WooCommerce/Classes/Emails/class-wc-emails.php to send the welcome email.

Is there an existing hook I can use or what’s the best way to do this.

I don’t want to create another welcome email function.

Thanks.

Answer

do_action('woocommerce_created_customer', $user_id, $new_customer_data, false);

1 Answer
1

There is no actions/filters to hook to. You need to override standard WC_Email_Customer_New_Account class and implement your own logic. To do it you need to create your own class which will inherit that class and register it.

class WPSE8170_Email_Customer_New_Account extends WC_Email_Customer_New_Account {

    function trigger( $user_id, $user_pass="", $password_generated = false ) {
        // do what you need here and then call parent method
        parent::trigger( $user_id, $user_pass, $password_generated );
    }

}

Now you need to register this class:

add_filter( 'woocommerce_email_classes', 'wpse8170_update_email_classes' );
function wpse8170_update_email_classes( $emails ) {
    $emails['WC_Email_Customer_New_Account'] = new WPSE8170_Email_Customer_New_Account();
    return $emails;
}

Leave a Reply

Your email address will not be published. Required fields are marked *