Home Forums WC Vendors Free Support Customising Commission (emails & backend) Reply To: Customising Commission (emails & backend)


Thanks for your help Ben. I gather you don’t do paid support tickets any longer? Apologies in advance for the long reply (PHP is very new to me)…

I will be moving to Pro soon (for various reasons), but I just want to make sure I’ll be able to solve this particular problem first if I do.

WCV Pro: “Multiple commission types such as percentage, percentage + fee, fixed fee, and even fixed fee + fee”. So what I’m trying to do is incorporate Paypal fees into the commission calculation; the problem being that these use the order total (not just the product price) so I need to get both the shipping total and the grand total for the order – I just can’t access them. I’m guessing I still won’t be able to do this in the Pro admin settings, right?

So here’s what I have for my commission calculation to illustrate (in my child theme’s functions.php):

add_filter( ‘wcv_commission_rate’, ‘my_wcv_commission_rate’, 10, 4 );
function my_wcv_commission_rate( $commission, $product_id, $product_price, $order ) {
$shipping_total = WC_Abstract_Order::calculate_shipping(); //get shipping total from order
$grand_total = WC_Abstract_Order::calculate_totals(); //get grand total from order
$commission_rate = WCV_Commission::get_commission_rate( $product_id ); //get product specific rate
$commission = $product_price * ( $commission_rate / 100 ); //compute commission
$per_item_addition = .5; //add £0.50 charge for each item sold — Change to whatever £ amount you want!
$commission = round( $commission, 2 ) – $per_item_addition; //round and remove per item fee.
$paypal_fee = .2 + ( .034 * $grand_total ); //paypal fees calculated on grand total, not product price
$commission = $commission – $paypal_fee; //subtract paypal fee.
$commission = $commission + $shipping_total; //add the shipping to commission due total
if ( $commission < 0 ) $commission = 0; //set to 0 if less than 0
return $commission;

Then I get this error logged:
Using $this when not in object context in /…/public_html/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-order.php on line 825

Those first 2 lines in the function are the issue and I get that $this works on the object in play when calculate_shipping() and calculate_totals() are called from WC_Abstract_Order and that’s why it’s not working (since there’s no object?).

I know you guys are super busy, but it feels like this should be a quick-fix for someone that knows PHP. Is it? Do I need to declare anything as global or am I barking up the wrong tree? Thanks in advance – I appreciate all the help I can get! (I’d be pulling my hair out if I had any)