slicewp_get_commissions()

Description

By default, the function returns an array of the latest registered commissions, or commissions matching the given arguments.

If the $count parameter (detailed below) is set to true, instead of the array with results, the function will return the results count.

Parameters

slicewp_get_commissions( $args = array(), $count = false );
  • $args (array)(optional) Array of arguments to retrieve commissions.
    • number (int) The number of commissions to query for. Defaults to 20.
    • offset (int) The number of commissions to offset the query by. Defaults to 0.
    • orderby (string) The commissions column to order results by. Default to “id”.
    • order (string) The order in which to return the results. Accepts “ASC” and “DESC” values. Defaults to “DESC”.
    • status (string) The status of the commission. Defaults to empty string.
    • affiliate_id (int) The ID of the affiliate tied to the commission. Defaults to 0.
    • parent_id (int) The ID of the parent commission.
    • reference (string) The specific reference to query commissions by. Usually the reference represents the order ID for which the commission has been generated. Defaults to empty string.
    • origin (string) The specific origin to query commissions by. Usually the origin is a string representing the abbreviation of the eCommerce plugin where the commission originated from. For example, for WooCommerce a commission will have the origin “woo”. Defaults to empty string.
    • include (array) An array of commission IDs to specifically return. Defaults to empty array.
  • $count (bool)(optional) Whether to return the total count of the results, instead of the actual results. Defaults to false.

Return

(array|int) Array of SliceWP_Commission objects or the results count if the $count parameter is set to true.

Examples

Get all commissions

By default, the function will return the last 20 commissions that have been registered. This example shows how you can retrieve all commissions.

$args = array(
    'number' => -1
);

$commissions = slicewp_get_commissions( $args );
// Returned value.

Array
(
    [0] => SliceWP_Commission Object
        (
            [id:protected] => 767
            [affiliate_id:protected] => 77
            [visit_id:protected] => 3814
            [date_created:protected] => 2021-08-08 18:16:46
            [date_modified:protected] => 2021-08-08 18:16:46
            [type:protected] => sale
            [status:protected] => unpaid
            [reference:protected] => 121
            [customer_id:protected] => 49
            [origin:protected] => woo
            [amount:protected] => 1.25
            [parent_id:protected] => 0
            [currency:protected] => USD
        )

    [1] => SliceWP_Commission Object
        (
            [id:protected] => 766
            [affiliate_id:protected] => 77
            [visit_id:protected] => 3814
            [date_created:protected] => 2021-08-08 18:14:30
            [date_modified:protected] => 2021-08-08 18:14:30
            [type:protected] => sale
            [status:protected] => unpaid
            [reference:protected] => 103
            [customer_id:protected] => 48
            [origin:protected] => woo
            [amount:protected] => 3.75
            [parent_id:protected] => 0
            [currency:protected] => USD
        )

    [2] => SliceWP_Commission Object
        (
            [id:protected] => 765
            [affiliate_id:protected] => 75
            [visit_id:protected] => 3812
            [date_created:protected] => 2021-08-08 18:11:08
            [date_modified:protected] => 2021-08-08 18:11:08
            [type:protected] => sale
            [status:protected] => unpaid
            [reference:protected] => 87
            [customer_id:protected] => 47
            [origin:protected] => woo
            [amount:protected] => 1.25
            [parent_id:protected] => 0
            [currency:protected] => USD
        )
)

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

$commissions = slicewp_get_commissions();

foreach ( $commissions as $commission ) {

    $affiliate_id = $commission->get( 'affiliate_id' );
    $status       = $commission->get( 'status' );

}

Get the count of all commissions

To retrieve the count for all generated commissions, you can query similarly to the previous example, but also set the $count parameter to true.

$args = array(
    'number' => -1
);

$commissions = slicewp_get_commissions( $args, true );
// Returned value.

767

Get all commissions for a certain affiliate

$args = array(
    'number'       => -1,
    'affiliate_id' => 10
);

$commissions = slicewp_get_commissions( $args );

Get all commissions that have a certain status

By default, the function will return commissions of all statuses. This example shows how you can return all commissions of a certain status.

$args = array(
    'number' => -1,
    'status' => 'unpaid'
);

$commissions = slicewp_get_commissions( $args );

Check if a commission has already been generated for a particular order in WooCommerce

The following example works the same for other integrations. The origin value will need to be adjusted depending on the integration you wish to query for.

$args = array(
    'origin'    => 'woo',
    'reference' => 123
);

$commissions = slicewp_get_commissions( $args, true );

if ( ! empty( $commissions ) ) {

    // Commission for order #123 in WooCommerce exists.

} else {

    // Commission for order #123 in WooCommerce does not exist.

}

Was this article helpful?

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

Can't find what you're looking for? We're here to help.

Open a support ticket