-
-
Save 10h30/cd3dc3ee6ffa6b62215f8d4cbf90fd4f to your computer and use it in GitHub Desktop.
AffiliateWP + WooCommerce - Alter the product commission depending on which category it's assigned to
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 | |
/** | |
* Change the commission amount if products belong to certain categories | |
* | |
*/ | |
function affwp_custom_wc_commission_per_category( $referral_amount, $affiliate_id, $amount, $reference, $product_id ) { | |
// You can specify an array of categories to alter the commission for. Separate by a comma and use either the term name, term_id, or slug | |
$categories = array( 'category-one', 5 ); | |
// Alter commission per product if they exist in the $categories array abve | |
if ( has_term( $categories, 'product_cat', $product_id ) ) { | |
$referral_amount = $amount * 0.3; // 30% commission for these categories | |
} | |
// or just specify 1 category | |
if ( has_term( 'some-category', 'product_cat', $product_id ) ) { | |
$referral_amount = 50; // $50.00 commission for a product in this category | |
} | |
// and another one | |
if ( has_term( 2, 'product_cat', $product_id ) ) { | |
$referral_amount = $amount * 0.8; // 80% commission for a product in this category | |
} | |
return $referral_amount; | |
} | |
add_filter( 'affwp_calc_referral_amount', 'affwp_custom_wc_commission_per_category', 10, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment