Primary

Referrals

The Affiliates_Referral_WordPress class provides methods that allow to record referrals.

evaluate

Referral evaluation method. This will create a new referral if an affiliate is creditable.

A referral is recorded for an affiliate if the system decides it is appropriate. This is the normal way to record referrals with Affiliates Pro and Enterprise.

Parameters

  • int $post_id (required)
  • string $description (optional) default: ”
  • array $data (optional) default: null
  • string $base_amount (optional) default: null
  • string $amount (optional) default: null
  • string $currency_id (optional) default: null
  • string $status (optional) default: null
  • string $type (optional) default: null
  • boolean $test (optional) default: false, if set to true no referral will be recorded

Usage:

$r = new Affiliates_Referral_WordPress();
$r->evaluate( $post_id, $description, $data, $base_amount, $amount, $currency_id, $status, $type, $reference, $test );

add_referrals

Referral recording method. This will record new referrals.
Referrals are recorded for each affiliate specified. Note that the affiliate(s) to be credited with referrals must be specified explicitly, the system will not choose the affiliates as opposed to the evaluate method.

Parameters

  • array $affiliate_ids (required)
  • int $post_id (required)
  • string $description (optional) default: ”
  • array $data (optional) default: null
  • string $base_amount (optional) default: null
  • string $amount (optional) default: null
  • string $currency_id (optional) default: null
  • string $status (optional) default: null
  • string $type (optional) default: null
  • boolean $test (optional) default: false, if set to true no referral will be recorded

Usage:

$r = new Affiliates_Referral_WordPress();
$r->add_referrals( $affiliate_ids, $post_id, $description, $data, $base_amount, $amount, $currency_id, $status, $type, $reference, $test );

Example

This is an example of how to suggest recording a referral and let the system decide whether it should credit an affiliate.

        // net order amount
        // the commission is calculated based on that
        $net_amount = 100;

        // appropriate currency code for the referral
        $currency = 'USD';

        // related post ID, order ID, ...
        $post_id = $order_id;

        $data = array(
            'order_id' => array(
                'title' => 'Order #',
                'domain' => YOUR_PLUGIN_DOMAIN,
                'value' => esc_sql( $order_id )
            ),
            'order_total' => array(
                'title' => 'Total',
                'domain' =>  YOUR_PLUGIN_DOMAIN,
                'value' => esc_sql( $net_amount )
            ),
            'order_currency' => array(
                'title' => 'Currency',
                'domain' =>  YOUR_PLUGIN_DOMAIN,
                'value' => esc_sql( $currency )
            )
        );

        $r = new Affiliates_Referral_WordPress();
        $description = sprintf( 'Order #%s', $order_id );
        $r->evaluate( $post_id, $description, $data, $net_amount, null, $currency, null, 'sale' );