Skip to content

Instantly share code, notes, and snippets.

@alexstandiford
Last active December 4, 2023 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexstandiford/822da901d44d905718bed16455694a54 to your computer and use it in GitHub Desktop.
Save alexstandiford/822da901d44d905718bed16455694a54 to your computer and use it in GitHub Desktop.
Set up an Custom AffiliateWP Integration
<?php
/**
* Registers a custom integration in AffiliateWP
**/
add_filter( 'affwp_extended_integrations', function( $integrations ) {
// Register the custom integration
$integrations['custom_integration'] = array(
'name' => 'Custom Integration',
'class' => 'Custom_Integration',
'file' => 'path/to/integration/Custom_Integration.php',
'enabled' => true,
'supports' => array( 'sales_reporting' ), // Only enable sales reporting if your plugin will actually support sales data methods in the base class!
);
return $integrations;
} );
<?php
/**
* Custom Integration Class
*
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class Custom_Integration
* Use this class to ext
*/
class Custom_Integration extends \Affiliate_WP_Base {
/**
* The context for referrals. This refers to the integration that is being used.
*
* @access public
* @since 1.2
*/
public $context = 'custom_integration';
/**
* Gets the total order count for this integration.
*
* @since 2.5
*
* @param string|array $date {
* Optional. Date string or start/end range to retrieve orders for. Default empty.
*
* @type string $start Start date to retrieve orders for.
* @type string $end End date to retrieve orders for.
* }
* @return int The total order count.
*/
// public function get_total_order_count( $date = '' ) {}
/**
* Gets the total sales for this integration.
*
* @since 2.5
*
* @param string|array $date {
* Optional. Date string or start/end range to retrieve orders for. Default empty.
*
* @type string $start Start date to retrieve orders for.
* @type string $end End date to retrieve orders for.
* }
* @return int|float The total sales.
*/
// public function get_total_sales( $date = '' ) {}
/**
* Retrieves a list of orders based on the provided dates.
*
* @since 2.5
*
* @param string|array $date {
* Optional. Date string or start/end range to retrieve orders for. Default empty.
*
* @type string $start Start date to retrieve orders for.
* @type string $end End date to retrieve orders for.
* }
* @return array
*/
// public function get_orders( $date = '' ) {}
/**
* Retrieves the order total for the specified order ID
*
* @since 2.5
*
* @param int $order_id The order ID
* @return float|int The order total
*/
// public function get_order_total( $order_id = 0 ) {}
}
new Custom_Integration;
@alexstandiford
Copy link
Author

alexstandiford commented Mar 31, 2021

You can also extend an existing integration, and override its functionality by extending any integration class directly.

EDD Example:

/**
 * Class Custom_Integration
 * Use this class to ext
 */
class Custom_Integration extends \Affiliate_WP_EDD {


	/**
	 * The context for referrals. This refers to the integration that is being used.
	 *
	 * @access  public
	 * @since   1.2
	 */
	public $context = 'custom_integration';

	public function add_pending_referral( $payment_id = 0, $payment_data = array() ) {
		parent::add_pending_referral( $payment_id, $payment_data );

		// Add custom actions here. See the Affiliate_WP_EDD integration class for more info.
	}

}

new Custom_Integration;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment