Skip to content

Instantly share code, notes, and snippets.

@bentasm1
Last active August 7, 2018 23:13
Show Gist options
  • Save bentasm1/20d959b38305f455d5dd to your computer and use it in GitHub Desktop.
Save bentasm1/20d959b38305f455d5dd to your computer and use it in GitHub Desktop.
WC Vendors Pro - Commission Rate depending on how much a product sells for
/* WC Vendors Pro -- No % for commission, just a tiered fee structure */
add_filter( 'wcv_commission_rate', 'my_wcv_commission_rate', 10, 5 );
function my_wcv_commission_rate( $commission, $product_id, $product_price, $order, $qty ) {
// First, reduce price to qty1 to do calculations
$product_price = $product_price / $qty;
// Second, run through the price and apply the right commission fee
if ( $product_price > 48.99 ) {
$commission_fee = 3.36;
} elseif ( $product_price >= 42.00 && $product_price <= 48.99 ) {
$commission_fee = 2.94;
} elseif ( $product_price >= 35.00 && $product_price <= 41.99 ) {
$commission_fee = 2.52;
} elseif ( $product_price >= 28.00 && $product_price <= 34.99 ) {
$commission_fee = 2.10;
} elseif ( $product_price >= 21.00 && $product_price <= 27.99 ) {
$commission_fee = 1.68;
} elseif ( $product_price >= 14.00 && $product_price <= 20.99 ) {
$commission_fee = 1.26;
} elseif ( $product_price >= 7.00 && $product_price <= 13.99 ) {
$commission_fee = 0.84;
} elseif ( $product_price >= 0.00 && $product_price <= 6.99 ) {
$commission_fee = 0.42;
}
// Third, set the commission to price - fee, since this is just a
// deduction no percentages are applied
$commission = $product_price - $commission_fee;
// Fourth, play it safe by setting to 0 if it's negative
if ( $commission < 0 ) $commission = 0;
// Fifth, round it so there's no half pennies
$commission = round( $commission * $qty, 2 );
// Finally, return the commssion total per product.
return $commission;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment