Posted on Leave a comment

affiliates_is_affiliate_by_id

If you are using Affiliates by itthinx, and you need to display different content per affiliates, then you are in correct place šŸ˜‰
This shortcode can help you:
add_shortcode ( 'affiliates_is_affiliate_by_id', 'affiliates_is_affiliate_by_id' );
function affiliates_is_affiliate_by_id($atts, $content = null) {
extract ( shortcode_atts ( array (
'id' => '0'
), $atts ) );
remove_shortcode ( 'affiliates_is_affiliate_by_id' );
$content = do_shortcode ( $content );
add_shortcode ( 'affiliates_is_affiliate_by_id', 'affiliates_is_affiliate_by_id' );
$output = "";
if (affiliates_user_is_affiliate ( get_current_user_id () )) {
if (affiliates_get_user_affiliate ( get_current_user_id () )[0] == $id) {
$output .= $content;
}
}
return $output;
}

Add this code in your functions.php theme file.
Example of use:
[affiliates_is_affiliate_by_id id="42"]
Only affiliate with id 42 can see this text.
[/affiliates_is_affiliate_by_id]
[affiliates_is_affiliate_by_id id="47"]
Only affiliate with id 47 can see this text.
[/affiliates_is_affiliate_by_id]

Posted on Leave a comment

[affiliates_username] shortcode

If you are using Affiliates by @itthinx and you need to display the referrer username, now you can use this shortcode:
add_shortcode( 'affiliates_username', 'affiliates_username_shortcode' );
function affiliates_username_shortcode( $atts ) {
  if ( !class_exists( "Affiliates_Service" ) ) {
    include_once( AFFILIATES_CORE_LIB . '/class-affiliates-service.php' );
  }
  $output = "";
  $affiliate_id = Affiliates_Service::get_referrer_id();
  if ( $affiliate_id ) {
    if ( $affiliate_id !== affiliates_get_direct_id() ) {
      if ( $user_id = affiliates_get_affiliate_user( $affiliate_id ) ) {
        if ( $user = get_user_by( 'id', $user_id ) ) {
          $output .= $user->user_login;
        }
      }
    }
  }
  return $output;
}

Posted on Leave a comment

[affiliates_show_list] shortcode

With this shortcode you can display a list of affiliates anywhere.
Add this code in your functions.php file and you could use the shortcode [affiliates_show_list]

add_shortcode( 'affiliates_show_list', 'affiliates_show_list' );
function affiliates_show_list( $atts ) {
global $wpdb;
$affiliates = affiliates_get_affiliates();
$output = "";
if ( is_array( $affiliates ) && ( sizeof( $affiliates ) > 0 ) ) {
$output .= '<ul>';
foreach ( $affiliates as $affiliate ) {
$output .= '<li>' . $affiliate['name'] . '</li>';
}
$output .= '</ul>';
}
return $output;
}

This is an extra function to Affiliates plugin by @itthinx.

Posted on Leave a comment

[aff_permanent_count] shortcode

If you are using Affiliates Pro / Enterprise with Affiliates Permanent by @itthinx, and you need to count how many customers are linked to an affiliate, this shortcode can help you:

add_shortcode( 'aff_permanent_count', 'aff_permanent_count' );
function aff_permanent_count( $atts ) {
global $wpdb;
$affiilate_id = Affiliates_Affiliate_WordPress::get_user_affiliate_id();
$meta_key = Affiliates_Permanent::REFERRER;
$meta_value = $affiilate_id;
$user_meta_query = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->usermeta WHERE meta_key=%s AND meta_value=%s", $meta_key, $meta_value ) );
return number_format_i18n($user_meta_query);
}

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://www.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]

Posted on 8 Comments

Affiliates Groups

Set different rates according to the affiliate’s group.

Requirements

Download

Changelog

2.0:
  • It is not a custom method.
  • Added custom rates by products
1.0:
  • Initial version is a Custom Method

Setup

Once you have configured Groups, Affiliates and the Woocommerce integration (with custom method product_rates)
affg-groups
affg-affiliates-woocommerce-integration
affg-affiliates-settings

Install and activate the Affiliates Groups plugin.
In Affiliates->Groups you can set the rates.
affgroups-setting

If you need a custom rate by product, you can do it in product page.
affg-product