Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WC Marketplace › split order after checkout depending on products vendors
- This topic has 5 replies, 3 voices, and was last updated 4 years, 12 months ago by WCFM Forum.
- AuthorPosts
- October 20, 2019 at 4:26 am #87751eadhassanParticipant
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 pluginHere 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(); }
- October 23, 2019 at 9:46 am #88365WCFM ForumMember
Hi,
Well, WCFM Marketplace already doing this internally but not visible to customers.
Between, why you want to do this specifically?
Thank You
- December 14, 2019 at 11:04 am #97426mailbpnmeParticipantThis reply has been marked as private.
- December 24, 2019 at 10:40 am #98885WCFM ForumMember
HI,
Which license plugin you are using for the purpose?
Thank You
- December 24, 2019 at 1:18 pm #98924mailbpnmeParticipantThis reply has been marked as private.
- December 28, 2019 at 11:51 am #99690WCFM ForumMember
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
- AuthorPosts
- The topic ‘split order after checkout depending on products vendors’ is closed to new replies.