Skip to content

Instantly share code, notes, and snippets.

@amdrew
Last active August 29, 2015 14:07
Show Gist options
  • Save amdrew/16d4662e92f7290de193 to your computer and use it in GitHub Desktop.
Save amdrew/16d4662e92f7290de193 to your computer and use it in GitHub Desktop.
AffiliateWP - Disable referrals on specific product categories in WooCommerce or Easy Digital Downloads
<?php
/**
* Disable referrals on specific product categories in Easy Digital Downloads
*/
function affwp_custom_edd_disable_referrals_on_categories( $referral_amount, $affiliate_id, $amount, $reference, $product_id ) {
// Array of categories to disable referrals for. Separate by a comma and use either the term name, term_id, or slug
$disabled_categories = array( 'category-one', 5 );
// Disable referral if product exists in array of categories
if ( has_term( $disabled_categories, 'download_category', $product_id ) ) {
$referral_amount = 0.00;
}
return $referral_amount;
}
add_filter( 'affwp_calc_referral_amount', 'affwp_custom_edd_disable_referrals_on_categories', 10, 5 );
<?php
/**
* Disable referrals on specific product categories in WooCommerce
*/
function affwp_custom_wc_disable_referrals_on_categories( $referral_amount, $affiliate_id, $amount, $reference, $product_id ) {
// Array of categories to disable referrals for. Separate by a comma and use either the term name, term_id, or slug
$disabled_categories = array( 'category-one', 5 );
// Disable referral if product exists in array of categories
if ( has_term( $disabled_categories, 'product_cat', $product_id ) ) {
$referral_amount = 0.00;
}
return $referral_amount;
}
add_filter( 'affwp_calc_referral_amount', 'affwp_custom_wc_disable_referrals_on_categories', 10, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment