Skip to content

Instantly share code, notes, and snippets.

@bentasm1
Last active August 12, 2023 21:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bentasm1/502fdc7186219583ce8f to your computer and use it in GitHub Desktop.
Save bentasm1/502fdc7186219583ce8f to your computer and use it in GitHub Desktop.
Charge a $ amount, instead of a % for commission, or charge $ AND % for commission in WC Vendors
Add the following code to your themes functions.php file.
FIXED $ AMOUNT FOR COMMISSIONS:
Rather than paying a percentage of each sale, you may wish to pay a set dollar amount per sale.
To do this, change the commission percentage in your settings to "5". If you do that, you will
send out $5 in commissions per item sold, rather than 5%. Of course, use your own figures
and test before going live.
add_filter( 'wcv_commission_rate', 'my_wcv_custom_filter', 10, 3 );
function my_wcv_custom_filter( $commission, $product_id, $product_price ) {
return WCV_Commission::get_commission_rate( $product_id );
}
FIXED $ AMOUNT PLUS PERCENTAGE FOR COMMISSIONS:
To charge a percentage PLUS a fixed dollar rate, customize this by changing
the $per_item_addition to a dollar amount of your choosing in the code below,
and the WC Vendors will charge the dollar amount plus the commission percentage
you have configured in your settings panel.
Credit for this code to nhadsall on our Help Forums!
add_filter( 'wcv_commission_rate', 'my_wcv_commission_rate', 10, 4 );
function my_wcv_commission_rate( $commission, $product_id, $product_price, $order ) {
$per_item_addition = .3; //add $0.30 charge for each item sold -- Change to whatever $ amount you want!
$commission_rate = WCV_Commission::get_commission_rate( $product_id ); //get product specific rate
$commission = $product_price * ( $commission_rate / 100 ); //compute commission
$commission = round( $commission, 2 ) - $per_item_addition; //round and remove per item fee.
if ( $commission < 0 ) $commission = 0; //set to 0 if less than 0
return $commission;
}
@AnandManish
Copy link

Hi!

Have you deducted $per_item_addition out of $commission twice by intent or is it just a typo? Am I missing something here?

$commission = round( $commission, 2 ) - $per_item_addition;
$commission = $commission - $per_item_addition;

@bentasm1
Copy link
Author

Good catch AnadManish -- Corrected. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment