Okay
  Public Ticket #3633973
b2bking()->is_b2b_user() not working for un-approved B2B Customers
Closed

Comments

  •  1
    Christian started the conversation

    Hello,

    I have the following code snippet in /woocommerce/emails/customer-new-account.php:

    // Get the user ID associated with the mail
    $user = get_user_by('login', $user_login );
    $user_id = $user->ID;

    // Check if $user_id is not empty before calling is_b2b_user()
    if ($user_id) {
        if (b2bking()->is_b2b_user($user_id)) {
            echo "<br>B2B user.<br>";
        } else {
            echo "<br>Not a B2B User.<br>";
        }
    } else {
        // Handle the case where $user_id is empty (e.g., guest customer)
        echo "<br>Guest customer (not registered).<br>";
    }

    Unfortunately, even for Not-Yet-Approved B2B-Users, the output of b2bking()->is_b2b_user($user_id) is false, therefore  "Not a B2B User.

    The expected output would be true, since we still have to handle him like a b2b-user. Is there a fix or workaround for this?

    Thank you!

    Attached files:  Screenshot 2024-04-23 at 18.53.35.png
      Screenshot 2024-04-23 at 18.53.07.png

  •  1,885
    WebWizards replied

    Hello Christian,

    Thank you for purchasing our plugin,


    Indeed that function only returns true for approved B2B users.

    If you would like to make that also accept accounts pending approval, you can change your code as follows:


    Replace this line:

    if (b2bking()->is_b2b_user($user_id)) {
    

    with:

    $approved = get_user_meta($user_id, 'b2bking_account_approved', true);
    if (b2bking()->is_b2b_user($user_id) || $approved === 'no') {
    

    Let me know if that can solve it for you,


    Kind regards,

    Stefan

  •  1
    Christian replied

    Thank you, that worked perfectly!