• Resolved pickme

    (@pickme)


    Hello,

    Using the code found in the following URL, an email notification can be sent to admin when new customer registers.

    https://docs.woocommerce.com/document/notify-admin-new-account-created/

    To what ‘admin’ term be changed to, in order for the email notification to be sent to Shop Manager rather than the admin?

    /**
     * Notify admin when a new customer account is created
     */
    add_action( 'woocommerce_created_customer', 'woocommerce_created_customer_admin_notification' );
    function woocommerce_created_customer_admin_notification( $customer_id ) {
      wp_send_new_user_notifications( $customer_id, 'admin' );
    }

    Thank you

    • This topic was modified 4 years, 5 months ago by pickme.
    • This topic was modified 4 years, 5 months ago by pickme.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support EastOfWest a11n

    (@eastofwest)

    Hi there!

    That function in the code you mention is a standard WordPress function, that accepts only 3 options for that parameter: admin, user, both (default is both). So while the role name you’re looking for is ‘shop_manager’ (as per this doc) it won’t work to simply replace ‘admin’ with it.

    If you look at the function wp_send_new_user_notification itself, you’ll see it’s just a wrapper for the function wp_new_user_notification, which is where the action happens:
    https://developer.www.ads-software.com/reference/functions/wp_new_user_notification/

    In that function there’s a filter, wp_new_user_notification_email_admin, which you can use to change the ‘to’ address. Something like this should work:

    
    /**
     * Notify any email when a new customer account is created
     */
    add_action( 'woocommerce_created_customer', 'woocommerce_created_customer_admin_notification' );
    function woocommerce_created_customer_admin_notification( $customer_id ) {
    
      add_action( 'wp_new_user_notification_email_admin', 'change_admin_email_to_store_manager_email' );
      function change_admin_email_to_store_manager_email( $wp_new_user_notification_email_admin ) {
        $wp_new_user_notification_email_admin['to'] = 'your_store_manager@email_address.com';
        return $wp_new_user_notification_email_admin;
      }
    
      wp_send_new_user_notifications( $customer_id, 'admin' );
    }
    
    Thread Starter pickme

    (@pickme)

    Hello @eastofwest!

    The code worked. Email notification when user registers is sent to email address specified and not to admin’s.

    Thank you for your excellent support!

    Plugin Support EastOfWest a11n

    (@eastofwest)

    Glad to hear helped!

    With that I’ll mark this thread as resolved. If you have any other questions, feel free to start a new thread.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Notify Shop Manager when a new customer account is created’ is closed to new replies.