Public Ticket #3633973

b2bking()->is_b2b_user() not working for un-approved B2B Customers

Closed
Comments
1 Ticket 1
Christian started the conversation 2 years ago on April 23, 2024 at 4:54pm

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!

2,762
KingsPlugins replied 2 years ago on April 24, 2024 at 5:20pm

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

Sign In