Best Multi Vendor Marketplace Plugin for WordPress › Forums › WCFM – Marketplace (WooCommerce Multivendor Marketplace) › Custom commission scheme based on WC Bookings block costs
- This topic has 13 replies, 2 voices, and was last updated 7 years, 10 months ago by
WCFM Forum.
- AuthorPosts
- December 20, 2018 at 10:06 am #40441
Pradeep M
GuestHello there,
Could someone kindly give me some directions on how to set up a vendor commission scheme based on WooCommerce Bookings’ block costs? I have a client who wants a site set up where the vendors get a percentage of the total of block cost as their commission. I would assume the logic would be:
– get product details and booking duration for each product
– calculate the total of block costs for each product
– assign the percentage, for example 70%, of those totals to respective vendorsI can find my way around the first two steps. It would be great if someone can show me how to put everything together so vendor commissions get updated every time a customer places an order.
Many thanks in advance!
- December 20, 2018 at 12:04 pm #40468
WCFM Forum
MemberHi,
I am a bit confused with your query.
Hope you have already set commission 70%
Now setup a booking product.
When customer will book that product 70% commission will be generated for vendor.
Why you require custom setup?
Thank You
- December 23, 2018 at 7:42 pm #40806
Pradeep M
GuestHello again,
Sorry it seems I have not explained it properly. What I need to do is give the vendors only a percentage of the total of “block cost” amount. Let’s say if the base cost is 400 and the block cost is 500. If the product total for a booking is 900, they will get 500 * 0.7 = 350. If the total is 1400, they will get 1000 * 0.7 = 700.
Here’s the code I’ve written for WooCommerce Product Vendors. It would be great if you could help me to get this to work with WCMV Marketplace.
//Calculate and add commissions
add_action(‘woocommerce_thankyou’, ‘mysite_woocommerce_order_status_completed’, 10, 2);function mysite_woocommerce_order_status_completed( $order_id) {
//Get Product Id and qty
$order = new WC_Order( $order_id );// Call the data store class so we can get bookings from the order.
$booking_data = new WC_Booking_Data_Store();
$booking_ids = $booking_data->get_booking_ids_from_order_id( $order_id );// If we have bookings go through each and update the status.
foreach ( $booking_ids as $booking_id ) {
$booking = get_wc_booking( $booking_id );
$product_id = $booking->get_product()->get_id(); //Get product ID from booking//These two lines need converting to WCMV Marketplace
$product_vendors = wp_get_post_terms($product_id,’wcpv_product_vendors’,array(‘fields’=>’ids’));
$vendor_id = (int)$product_vendors[0]; //Vendor id$block_cost = get_post_meta($product_id, ‘_wc_booking_block_cost’, false)[0]; //Booking Block Costs
$start_date = $booking->get_start_date();
$end_date = $booking->get_end_date();//Calculate booking duration for the product
$date_diff = strtotime($end_date) – strtotime($start_date);
$duration = round($date_diff / (60*60*24));//Calculate total commission
if ($duration > 4 ) {
$total_commission = ($block_cost + ($block_cost*75/100)) *0.5;
} else {
$total_commission = $block_cost*0.5;
}//The following commission assignment needs converting to WCMV Marketplace
global $wpdb;
$table_name = $wpdb->prefix .’wcpv_commissions’;
$update_commission = $wpdb->query($wpdb->prepare(“UPDATE $table_name SET total_commission_amount=%d WHERE order_id = %d AND vendor_id = %d”,$total_commission,$order_id,$vendor_id));do_action( ‘wcpv_commissions_updated’ );
}
}Thanks and regards,
- December 24, 2018 at 7:02 am #40893
WCFM Forum
MemberHi,
Here is your code for WCFM Marketplace –
add_filter( 'wcfmmp_order_item_commission', function( $item_commission, $vendor_id, $product_id, $variation_id, $item_price, $quantity, $commission_rule ) { $product_type = WC_Product_Factory::get_product_type( $product_id ); if ( 'booking' == $product_type ) { $bookable_product = new WC_Product_Booking( $product_id ); $booking_base_cost = $bookable_product->get_cost( 'edit' ); $item_price -= $booking_base_cost; // Generate Commission on this Price if( $commission_rule && is_array( $commission_rule ) ) { switch( $commission_rule['mode'] ) { case 'percent': $item_commission = $item_price * ((float) $commission_rule['percent']/100); break; case 'fixed': $item_commission = (float) $commission_rule['fixed'] * $quantity; break; case 'percent_fixed': $item_commission = (float) $item_price * ((float) $commission_rule['percent']/100); $item_commission += (float) $commission_rule['fixed'] * $quantity; break; } $admin_fee_mode = apply_filters( 'wcfm_is_admin_fee_mode', false ); if( $admin_fee_mode ) { $item_commission = (float) $item_price - (float) $item_commission; } } } return $item_commission; }, 50, 7 );Thank You
- December 24, 2018 at 7:05 am #40894
WCFM Forum
MemberHi,
Keep it more simple, don’t use previous code. Just use this ->
add_filter( 'wcfmmp_order_item_price', function( $item_price, $product_id, $variation_id, $quantity, $vendor_id, $order_id ) { $product_type = WC_Product_Factory::get_product_type( $product_id ); if ( 'booking' == $product_type ) { $bookable_product = new WC_Product_Booking( $product_id ); $booking_base_cost = $bookable_product->get_cost( 'edit' ); $item_price -= $booking_base_cost; } return $item_price; }, 50, 6 );Thank You
- December 24, 2018 at 2:17 pm #40950
Pradeep M
GuestHello again,
Many thanks for the snippet. It works but with some issues. Basically in my setup, customers (renters) can rent items from multiple vendors for a single order. When I add 2 items (2 separate bookings) for a single order, it calculates and assigns the commission correctly to the first one but the other item, throughout the order, appears without a vendor – see the screenshot (https://www.awesomescreenshot.com/image/3798692/bc0630b513baa08ced5ce9a599660637). It doesn’t appear on the vendor’s account either.
I have a couple of other related questions but I’ll hold them until I get this sorted. Is there a way for me to search your forum so I can see if anyone else has asked these questions before?
Many thanks in advance!
- December 24, 2018 at 2:37 pm #40956
WCFM Forum
MemberHi,
I checked your image and found that second item is not a vendor’s product.
Then why you are expecting commission calculation for that?Thank You
- December 24, 2018 at 7:32 pm #40992
Pradeep M
GuestThat is the problem! It’s a vendor’ item that belongs to a different vendor but it’s coming up without vendor’s details on the order. And that order doesn’t appear on that vendor’s account either.
- December 25, 2018 at 5:27 am #41024
WCFM Forum
MemberHi,
“item that belongs to a different vendor but it’s coming up without vendor’s details on the order”
– It’s impossible. Is that vendor previously created with your old multi-vendor plugin?Thank You
- December 26, 2018 at 10:50 am #41186
Pradeep M
GuestNo this is a brand-new instance, created just to test the capabilities of WCMV Marketplace. I just placed a new order by alternating the products and again it strips the vendor details from the second product in the order. Please see the screenshot. I am testing this on a local instance, otherwise I could’ve give you the access to have a look.
https://www.awesomescreenshot.com/image/3799709/5d6c58b87800ce7e1b34bae395f8be61
- December 26, 2018 at 11:29 am #41188
Pradeep M
GuestHere is a list of active plugins I have. I have the same plugins activated for the instance that is running WC Product Vendors plugin and it is working fine.
https://www.awesomescreenshot.com/image/3799743/2468360ef0eef2419798e9cc044bb662
- December 26, 2018 at 1:31 pm #41212
WCFM Forum
MemberHi,
WCFM Marketplace 2.0.4 has just updated.
Kindly update yours and take a look now.
Thank You
- December 27, 2018 at 11:47 am #41369
Pradeep M
GuestHello,
That update did the trick and it is working fine now. Many thanks! I have a couple more questions and I will post them separately after searching the forums.
Best regards,
- December 27, 2018 at 12:06 pm #41375
WCFM Forum
MemberThat’s great 🙂
Sure, feel free to ask me those anytime.
Thank You
- AuthorPosts
- The topic ‘Custom commission scheme based on WC Bookings block costs’ is closed to new replies.

