Need if-then-else ... I think (revised)

I have a PHP snipped which generates a membership number, whether the person is registering for a membership or ordering a workshop through WooCommerce. I need only members -
if( pmpro_hasMembershipLevel()) - to receive a membership number. How do I assign everyone else (e.g woo commerce customers) a generic designation “Customer”

Here is my logic…

Goal: Generate member_number when a MEMBER is registered, otherwise enter default CUSTOMER notation

  1. Check if the user has an active membership level.
    if( pmpro_hasMembershipLevel()

  2. if membership level exists then they get a membership number which is the same as the user_id

  3. otherwise assign $asta_number = “Customer”;

—code in use is below—

{function generate_asta_number($user_id)
$asta_number = get_user_meta($user_id, “asta_number”, true);

// Update the user’s member number when they first signup for a membership.

$asta_number = $user_id;
update_user_meta($user_id, "asta_number", $asta_number);
	
	//save to user meta
	update_user_meta($user_id, "asta_number", $asta_number);
	
	return $asta_number;
}

I tried to edit previous post but accidentally deleted. Apologies.

function generate_asta_number($user_id) {
    // Check if the user has an active membership level
    if (pmpro_hasMembershipLevel()) {
        // If a membership level exists, then they get a membership number which is the same as the user_id
        $asta_number = $user_id;
    } else {
        // Otherwise, assign a generic designation for customers
        $asta_number = "Customer";
    }

    // Save to user meta
    update_user_meta($user_id, "asta_number", $asta_number);

    return $asta_number;
}

try this …

Sponsor our Newsletter | Privacy Policy | Terms of Service