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.
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;
}