Created
May 28, 2015 03:27
-
-
Save digitalchild/3b75a5ff599357f0a4b3 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 ); | |
} |
Easy, just add it to your themes functions.php file. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please let me know how to implement this in wcvendor local installation with latest version