Split by taxonomy
-
I use a custom taxonomy for internal use and for a different organization on the frontend.
It’s possible use a custom taxonomy for split the shipping in the order?https://ww.wp.xz.cn/plugins/multiple-packages-for-woocommerce/
-
ok, i have do it the code for this 🙂
$packages_terms = array(); foreach ( WC()->cart->get_cart() as $item ) { //here the taxonomy $terms = get_the_terms( $item[ 'product_id' ], 'shop_vendor' ); if ( $item[ 'data' ]->needs_shipping() ) { $packages_terms[ $terms[ 0 ]->name ][] = $item; } } // Put inside packages foreach ( $packages_terms as $term_name => $items ) { $packages[ ] = array( 'contents' => $items, 'contents_cost' => array_sum( wp_list_pluck( $items, 'line_total' ) ), 'applied_coupons' => WC()->cart->applied_coupons, 'destination' => array( 'country' => WC()->customer->get_shipping_country(), 'state' => WC()->customer->get_shipping_state(), 'postcode' => WC()->customer->get_shipping_postcode(), 'city' => WC()->customer->get_shipping_city(), 'address' => WC()->customer->get_shipping_address(), 'address_2' => WC()->customer->get_shipping_address_2() ) ); // Determine if 'ship_via' applies $key = $item[ 'data' ]->get_shipping_class_id(); if ( $free_classes && in_array( $key, $free_classes ) ) { $packages[ $term_name ][ 'ship_via' ] = array( 'free_shipping' ); } elseif ( count( $package_restrictions ) && isset( $package_restrictions[ $key ] ) ) { $packages[ $term_name ][ 'ship_via' ] = $package_restrictions[ $key ]; } }Thanks, I’m glad you were able to write something up that worked for you! I can definitely write this idea down and make it possible to do something like this from the settings page sometime in the future.
Daniele “Mte90” Scasciafratte
I tried to use your code but I’m get this massage :
Fatal error: Cannot use object of type WP_Error as array
how did you mange to make it work?
line error?
can you please upload to me the plugin with your edition Daniele “Mte90” Scasciafratte
because when I put this on my theme function.php I get
Fatal error: Cannot use object of type WP_Error as arrayand yes its line error
Daniele what does exactly your code do?
split it by what?
I have a multi vendor shop and I want to split it by seller
how can I do that?
This code need to be placed in the plugin file not in the function php. I also use this for a multivendor system 🙂
Ok Im sorry but where exactly should i put this code i mean where inside the plugin please if you can upload the pluging with the code i would appreciate it or you could send it to my email
malik @ basalamah . netThanks
when i replace the code with the per product in the plugin
i got this error
Fatal error: Cannot use object of type WP_Error as array in /home/***/***.com/wp-content/plugins/multiple-packages-for-woocommerce/multiple-packages-shipping.php on line 65
this line : $packages_terms[ $terms[ 0 ]->name ][] = $item;
can you help me please?
This is the content of multiple-packages-shipping.php http://pastebin.com/inUnWNhR with this code that work 🙂
thanks
I changed something in the code and now its working per seller
one problem only when customer or seller get the email there is no details about shipping
have you fixed this issue ?
I did not know of this problem :-/
so now what happens with you when customer for example
choose for product 1 aramex shipping
and for product 2 fedex shippinghow will vendor know what shipping method do the customer choose?
in my case i don’t have this problem.
I have set up a shipment based on the price for vendor.
The topic ‘Split by taxonomy’ is closed to new replies.