split order after checkout depending on products vendors

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!

Multi Vendor Marketplace Plugin | WCFM Marketplace Forums WC Marketplace split order after checkout depending on products vendors

Viewing 5 reply threads
  • Author
    Posts
    • #87751
      eadhassan
      Participant

      I need to split order before thank you page view depending on products vendors
      for example If the order contains 5 products from different vendors
      – 2 products from X vendor
      – 2 products from Z vendor
      – 1 product from S vendor
      so I need to generate 3 different orders from the original order data and store the generated orders instead of the original order
      I’m using WCFM marketplace plugin, and I found a premium plugin that doing this but for another multi-vendor plugin

      Here is what I done in code, but I get Internal Server Error

          add_action( 'woocommerce_checkout_create_order', 'HF_before_checkout_create_order', 20, 2 ); 
          function HF_before_checkout_create_order( $order, $data ){
            global $wpdb;
            global $WCFM;
            global $woocommerce;
      
            $vendors = array();
      
            foreach( $order->get_items() as $key => $item ) {
              $product_id = $item['product_id'];
              $vendor = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product( $product_id );
              if( $vendor ) {
                $vendors[] = $vendor;
                // wc_delete_order_item( $key );
              }
      
              if( count($vendors) ) :
      
                foreach( $vendors as $vendor_order ) :
      
                    $order_seller = new WC_Order();
      
                    foreach( $data['line_items'] as $line_item ) {
                        $args = $line_item['args'];
                        $product = wc_get_product( isset($args['variation_id']) && $args['variation_id'] > 0 ? $$args['variation_id'] : $args['product_id'] );
                        $product_vendor = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product( $product->ID );
                        if( $product_vendor == $vendor_order ) :
                          $order_seller->add_product( $product, $line_item['quantity'], $line_item['args'] );
                        endif;
                    }
      
                  $order_seller->set_address( $order->get_address( 'billing' ), 'billing' );
                  $order_seller->set_address( $order->get_address( 'shipping' ), 'shipping' );
      
                  $order_seller->calculate_taxes();
                  $order_seller->calculate_totals();
                  $order_seller->save();
      
                endforeach;
      
              endif;
            }
      
            $order->update_status(
              'cancelled',
              __( 'This order has been splitted to separate orders' )
            );
            $history = $order->addStatusHistoryComment('Order marked as cancelled.', false);
            $history->setIsCustomerNotified(false);
            $order->save();
                 
          }
    • #88365
      WCFM Forum
      Keymaster

      Hi,

      Well, WCFM Marketplace already doing this internally but not visible to customers.

      Between, why you want to do this specifically?

      Thank You

    • #97426
      mailbpnme
      Participant
      This reply has been marked as private.
    • #98885
      WCFM Forum
      Keymaster

      HI,

      Which license plugin you are using for the purpose?

      Thank You

    • #98924
      mailbpnme
      Participant
      This reply has been marked as private.
    • #99690
      WCFM Forum
      Keymaster

      OK, but WCFM not yet compatible with this.

      We are going to add this license plugin’s compatibility in next update – https://woocommerce.com/products/software-add-on/

      Thank You

Viewing 5 reply threads
  • The topic ‘split order after checkout depending on products vendors’ is closed to new replies.