Skip to content

Instantly share code, notes, and snippets.

@fervous
Forked from digitalchild/gist:3b75a5ff599357f0a4b3
Created March 22, 2017 23:44
Show Gist options
  • Save fervous/01c7d017fe6eaaeedbdf8c352701fdfa to your computer and use it in GitHub Desktop.
Save fervous/01c7d017fe6eaaeedbdf8c352701fdfa to your computer and use it in GitHub Desktop.
Vendor Commission based on Category fixed price
<?php
add_filter( 'wcv_commission_rate', 'my_wcv_commission_rate', 10, 4 );
function my_wcv_commission_rate( $commission, $product_id, $product_price, $order ) {
$terms = get_the_terms( $product_id, 'product_cat' );
// Loop through the categories
// It will break on the first category assigned
foreach ( $terms as $term ) {
switch ( strtolower( $term->name ) ) {
case 't-shirts':
$commission = $product_price - 12;
break;
case 'canvas':
$commission = $product_price - 10;
break;
case 'hats':
$commission = $product_price - 17;
break;
case 'hoodies':
$commission = $product_price - 26;
break;
// Some default if it fails all the above.
default:
$commission = $product_price - 2;
break;
}
}
return round( $commission, 2 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment