Customer::get_group_id()
Summary
Get the customer group ID assigned to the user.
Description
Value will be fetched from cache if available, otherwise from the API.
Return
(int|null)
Source
File: src/BigCommerce/Accounts/Customer.php
public function get_group_id() { $customer_id = is_user_logged_in() ? get_user_option( self::CUSTOMER_ID_META, $this->wp_user_id ) : 0; if ( ! $customer_id ) { /** * This filter is documented in src/BigCommerce/Accounts/Customer.php */ return apply_filters( 'bigcommerce/customer/group_id', null, $this ); } $transient_key = sprintf( 'bccustomergroup%d', $customer_id ); $group_id = get_transient( $transient_key ); if ( empty( $group_id ) ) { // Couldn't find in cache, retrieve from the API $profile = $this->get_profile(); $group_id = isset( $profile['customer_group_id'] ) ? absint( $profile['customer_group_id'] ) : 0; $expiration = HOUR_IN_SECONDS; // TODO: a future webhook to flush this cache when the customer's group changes if ( $group_id === 0 ) { set_transient( $transient_key, 'zero', $expiration ); // workaround for storing empty values in cache } else { set_transient( $transient_key, $group_id, $expiration ); } } if ( $group_id === 'zero' ) { $group_id = 0; } /** * Filter the group ID associated with the customer * * @param int|null $group_id The customer's group ID. Null for guest users. * @param Customer $customer The Customer object */ $group_id = apply_filters( 'bigcommerce/customer/group_id', $group_id, $this ); return absint( $group_id ); }