Last active
December 4, 2023 18:15
-
-
Save alexstandiford/822da901d44d905718bed16455694a54 to your computer and use it in GitHub Desktop.
Set up an Custom AffiliateWP Integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also extend an existing integration, and override its functionality by extending any integration class directly.
EDD Example: