# Higher Commission Rate for a User Role (AffiliateWP)

> Gives affiliates with a specific user role, such as "partner" or "wholesale", a different commission rate from the global AffiliateWP rate, unless they have a custom rate set on their profile.

- Type: PHP
- Runs: Run everywhere
- Category: [Plugin Integrations](https://wpide.com/library/category/integrations/)
- Tags: affiliatewp, commissions, roles
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/affwp-rate-by-role/

## Code

```php
$wpide_role = 'partner'; // User role that gets the special rate.
$wpide_rate = 30;        // Rate for that role (30 = 30% for percentage rates).

add_filter( 'affwp_get_affiliate_rate', function ( $rate, $affiliate_id ) use ( $wpide_role, $wpide_rate ) {
    if ( ! function_exists( 'affwp_get_affiliate' ) ) {
        return $rate;
    }

    $affiliate = affwp_get_affiliate( $affiliate_id );

    if ( ! $affiliate || '' !== (string) $affiliate->rate ) {
        return $rate; // A custom rate on the affiliate wins.
    }

    $user = get_userdata( $affiliate->user_id );

    if ( $user && in_array( $wpide_role, (array) $user->roles, true ) ) {
        $type = function_exists( 'affwp_get_affiliate_rate_type' ) ? affwp_get_affiliate_rate_type( $affiliate_id ) : 'percentage';
        return 'percentage' === $type ? $wpide_rate / 100 : $wpide_rate;
    }

    return $rate;
}, 10, 2 );
```

## Notes

The rate uses the affiliate's rate type (percentage or flat). Affiliates with their own rate in AffiliateWP keep it.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Higher Commission Rate for a User Role (AffiliateWP)" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
