Getting Started

Affiliate Area

Troubleshooting

Miscellaneous

Integrations

Pre-sale Questions

Developers

Functions

Filters

slicewp_get_affiliate_by_user_id()

Description

Retrieves an affiliate from the database by the given user ID. Because an affiliate must also have a corresponding WP_User, you can retrieve an affiliate by using the user ID.

Parameters

slicewp_get_affiliate_by_user_id( $user_id );
  • $user_id (int)(required) The user ID associated with the affiliate.

Return

(SliceWP_Affiliate|null) A SliceWP_Affiliate object containing the affiliate data, or null if there is no affiliate data associated with the given user ID.

Example

The following example shows how you can retrieve the affiliate data object corresponding to the user with the ID of 22.

$affiliate = slicewp_get_affiliate_by_user_id( 22 );
// Returned value.

SliceWP_Affiliate Object
(
    [id:protected] => 10
    [user_id:protected] => 22
    [date_created:protected] => 2021-08-26 10:48:22
    [date_modified:protected] => 2021-08-26 10:48:22
    [status:protected] => active
    [payment_email:protected] => john_doe@johndoe.com
    [website:protected] => https://johndoe.com/
)

Because the SliceWP_Affiliate object’s properties are protected, to access them you can use the get( $property_name ) method.

$affiliate = slicewp_get_affiliate_by_user_id( 22 );

if ( ! is_null( $affiliate ) ) {

    $user_id = $affiliate->get( 'user_id' );
    $status  = $affiliate->get( 'status' );

}

Was this article helpful?

Do you have any feedback or suggestions to improve this page?