Posted on Leave a comment

Affiliates Custom Method – if coupon

Custom method to Affiliates plugin : set 20% if coupon is not used, otherwise 10%.
If you need to customize your values, simply you need to change these static vars:

public static $default_rate = 0.20;
public static $if_coupon_rate = 0.10;

Affiliates_Custom_Method_if_coupon-1.1

[php]
/**
* Plugin Name: Affiliates Custom Method – If Coupons
* Description: Custom method: set different rates if a coupon is used.
* Version: 1.1
* Author: eggemplo
* Author URI: http://eggemplo.com
*/
class ACM {

public static $default_rate = 0.20;
public static $if_coupon_rate = 0.10;

public static function init() {
if (class_exists ( ‘Affiliates_Referral’ )) {
Affiliates_Referral::register_referral_amount_method ( array ( __CLASS__, ‘if_coupon’ ) );
}
}

/**
* Custom referral amount method implementation.
*
* @param int $affiliate_id
* @param array $parameters
*
*/
public static function if_coupon($affiliate_id = null, $parameters = null) {
require_once( AFFILIATES_CORE_LIB . ‘/class-affiliates-service.php’ );

$result = self::$default_rate;
if ( $custom_rate = Affiliates_Affiliate::get_attribute( Affiliates_Service::get_referrer_id(), ‘referral.rate’ ) ) {
$result = $custom_rate;
}
if (isset ( $parameters [‘post_id’] )) {
$order_id = intval( $parameters[‘post_id’] );

if ( class_exists( ‘WC_Order’ ) ) {
$order = new WC_Order();
} else {
$order = new woocommerce_order();
}
if ( $order->get_order( $order_id ) ) {
if( $order->get_used_coupons() ) {
$result = self::$if_coupon_rate;
}
}
}
$result = bcmul( $result, $parameters[‘base_amount’], 2 );

return $result;
}
}

add_action ( ‘init’, array ( ‘ACM’, ‘init’ ) );
[/php]

Leave a Reply

Your email address will not be published. Required fields are marked *