Skip to content

Instantly share code, notes, and snippets.

@mircian
Created April 21, 2017 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mircian/17fce0fb44b71504e4b9e41059f96be3 to your computer and use it in GitHub Desktop.
Save mircian/17fce0fb44b71504e4b9e41059f96be3 to your computer and use it in GitHub Desktop.
Add a special commission for a specific gateway
<?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) {
$card_gateways = array('stripe');
$author = WCV_Vendors::get_vendor_from_product( $product_id );
if ( WCV_Vendors::is_vendor( $author ) ) {
// check if the order was placed using the card!
if ( in_array($order->payment_method, $card_gateways) ) {
// the commission you want to add - switch to whatever logic fits
$card_commission_rate = 2;
// add the card commission
$card_commission = $product_price * ( intval( $card_commission_rate ) / 100 );
$card_commission = round( $card_commission, 2 );
// remove the commission from the payment that goes to the vendor
$commission -= $card_commission;
}
}
return $commission;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment