Skip to content

Instantly share code, notes, and snippets.

@amdrew
Created December 3, 2014 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amdrew/c149510eef862f822b1f to your computer and use it in GitHub Desktop.
Save amdrew/c149510eef862f822b1f to your computer and use it in GitHub Desktop.
AffiliateWP + WooCommerce - Alter the product commission depending on which category it's assigned to
<?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