Public Ticket #3768558

Accounts Approval Notification

Closed
Comments
7 Tickets
Hassan started the conversation 2 years ago on November 21, 2024 at 3:22pm

On my store users are registered via third party user registration plugin , I manually set the meta fields to assign user in B2B GROUP and I also want its account to approved manually I am setting the following meta fields:
- b2bking_b2buser = yes
- b2bking_customergroup = 123
- b2bking_account_approved = no

customer receives the the email notification of Thank you for registration and your accounts need approval , but for some unknown reason admin is not receiving any email that a new customer account needs manual approval, also will you please be able to provide me the code snippet through which I can send this email to admin.

2,762
KingsPlugins replied 2 years ago on November 21, 2024 at 8:55pm

Hello Hassan,

Thank you for purchasing our plugin,

 

I am not entirely sure why that email is not being sent, but probably the other plugin is not triggering the right hook / or it triggers it too quickly (before the b2bking_account_approved meta is set).

I believe we could use a code snippet to force trigger it. We would need to be able to run some PHP code during the account creation:

do_action('b2bking_new_user_requires_approval', 1234, '', '');

(here 1234 has to be replaced with the ID of the customer, $customer_id).

 

Can you let me know what the other registration plugin is? I can check its documentation.

Or if you can share a backend access to the site, or a staging clone site, I can also work on this directly and try to get it working,

 

Kind regards,

Stefan

1
7 Tickets
Hassan replied 2 years ago on November 22, 2024 at 8:02am

Hi Stefan,

Thank you for the code snippet, I am using User Registration plugin for the registration feature, and it allows me to set the meta filed along with the registration form so I am setting the meta fields with the form, also I have another form which is completely custom and when user is registers through this form I also want to send email notifications to both customer and admin. I used your snippet but still email is not sent to admin .

Below is the complete code of how I am saving the user and its meta.

// Inserting the user 
    $user_data = array(
        'user_login'    => $email,
        'user_pass'     => $hashed_password,
        'user_email'    => $email,
        'first_name'    => $first_name,
        'last_name'     => $last_name,
        'role'          => 'customer',
    );

    $user_id = wp_insert_user($user_data);

 // Checking for errors
    if (is_wp_error($user_id)) {
        wp_send_json_error($user_id->get_error_message());
    }

update_user_meta($user_id, 'ur_user_status', 0);
update_user_meta($user_id, 'ur_login_option', 'admin_approval');

//B2B King meta
update_user_meta($user_id, 'b2bking_b2buser', 'yes');
update_user_meta($user_id, 'b2bking_customergroup', '9554');
update_user_meta($user_id, 'b2bking_account_approved', 'no');

//Email notification to Admin
do_action('b2bking_new_user_requires_approval', $user_id, '', '');

// Respond with success
wp_send_json_success('Form submitted successfully!');

 
I also want to send the notification to Customer as well if I could be able to work it in this custom form may be than I can hook into the registration action of the User Registration Plugin and perform action there as well .

Thanks & Regards



  

2,762
KingsPlugins replied 2 years ago on November 25, 2024 at 4:23pm

Hi again,

Your code appears correct. I am not sure what the issue is unfortunately.

I did test "do_action('b2bking_new_user_requires_approval', $user_id, '', ''); on my local test site and I do see the email sent in my tests.

This is probably already set, but just to check: Please also make sure the "new user requires approval" email is enabled in WooCommerce -> Settings -> Emails.

 

Other than that, I'm not sure what the issue is. Maybe something with the load / hook sequence but it gets complex. Possible to share a backend access to the site or a staging site, so we can check this directly?

 

Regarding sending an email to the customer, would that be just a general welcome email? if so, I suggest trying this function: https://pastecode.io/s/phq1go27 usage: send_woocommerce_welcome_email($customer_id);

Sign In