-
-
Save fervous/01c7d017fe6eaaeedbdf8c352701fdfa to your computer and use it in GitHub Desktop.
Vendor Commission based on Category fixed price
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 | |
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