Diwali

Wishing you joy this Diwali and Halloween! Enjoy up to 20% OFF on all addons!

Claim Offer
04Day 21Hr 52Min 53Sec
Diwali

Custom commission scheme based on WC Bookings block costs

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Viewing 12 reply threads
  • Author
    Posts
    • #40441
      Pradeep M
      Guest

      Hello 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 vendors

      I 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!

    • #40468
      WCFM Forum
      Member

      Hi,

      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

      • #40806
        Pradeep M
        Guest

        Hello 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,

    • #40893
      WCFM Forum
      Member

      Hi,

      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

    • #40894
      WCFM Forum
      Member

      Hi,

      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

    • #40950
      Pradeep M
      Guest

      Hello 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!

    • #40956
      WCFM Forum
      Member

      Hi,

      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

    • #40992
      Pradeep M
      Guest

      That 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.

    • #41024
      WCFM Forum
      Member

      Hi,

      “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

    • #41186
      Pradeep M
      Guest

      No 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

    • #41188
      Pradeep M
      Guest

      Here 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

    • #41212
      WCFM Forum
      Member

      Hi,

      WCFM Marketplace 2.0.4 has just updated.

      Kindly update yours and take a look now.

      Thank You

    • #41369
      Pradeep M
      Guest

      Hello,

      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,

    • #41375
      WCFM Forum
      Member

      That’s great 🙂

      Sure, feel free to ask me those anytime.

      Thank You

Viewing 12 reply threads
  • The topic ‘Custom commission scheme based on WC Bookings block costs’ is closed to new replies.