Skip to content

Instantly share code, notes, and snippets.

@mircian
Created November 24, 2017 07:48
Show Gist options
  • Save mircian/0001f998906573518bcce751ea8df85e to your computer and use it in GitHub Desktop.
Save mircian/0001f998906573518bcce751ea8df85e to your computer and use it in GitHub Desktop.
<?php
add_filter('wcv_commission_rate', 'm_commission_update', 20, 5);
/**
* @param $commission
* @param $product_id
* @param $product_price
* @param $order
* @param $qty
*
* @return float
*/
function m_commission_update($commission, $product_id, $product_price, $order, $qty) {
$author = WCV_Vendors::get_vendor_from_product( $product_id );
if ( WCV_Vendors::is_vendor( $author ) ) {
// the commission you want to add - switch to whatever logic fits
$card_commission_rate = 1;
// Maximum commission ( optional )
$max_commission = 299;
// add the card commission
$m_commission = $product_price * ( intval( $card_commission_rate ) / 100 );
$m_commission = round( $m_commission, 2 );
// Comment this out if don't want a cap
if ( $m_commission >= $max_commission ) {
$m_commission = $max_commission;
}
// remove the commission from the payment that goes to the vendor
$commission -= $m_commission;
}
return $commission;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment