Skip to content

Instantly share code, notes, and snippets.

@fervous
Created May 2, 2018 21:57
Show Gist options
  • Save fervous/b5e15eb34aa79366d130b3bcd731335c to your computer and use it in GitHub Desktop.
Save fervous/b5e15eb34aa79366d130b3bcd731335c to your computer and use it in GitHub Desktop.
wc vendors woocommerce bookings commission fee per person
add_filter( 'wcv_commission_rate', 'my_wcv_commission_rate', 10, 4 );
function my_wcv_commission_rate( $commission, $product_id, $product_price, $order ) {
$product = wc_get_product($product_id);
$commission_amount = get_post_meta( $product_id, 'wcv_commission_amount', true );
$items = $order->get_items();
foreach( $items as $item ) {
$booking_ids = WC_Booking_Data_Store::get_booking_ids_from_order_item_id( $item->get_id() );
foreach( $booking_ids as $booking_id ) {
$booking = new WC_Booking($booking_id);
if ( $product_id === $booking->get_product()->get_id() ){
$person_count = array_sum( $booking->get_person_counts() );
$commission = $commission_amount * $person_count;
$commission = round( $commission, 2 ); //round and remove per item fee.
}
}
}
if ( $commission < 0 )
$commission = 0; //set to 0 if less than 0
return $commission;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment