Advertisement
Guest User

Untitled

a guest
Mar 13th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. /* Free Shipment option */
  2.  
  3. add_filter( 'woocommerce_cart_shipping_packages', 'bulky_woocommerce_cart_shipping_packages' );
  4.  
  5. function bulky_woocommerce_cart_shipping_packages( $packages ) {
  6. // Reset the packages
  7. $packages = array();
  8.  
  9. // Bulky items
  10. $bulky_items = array();
  11. $regular_items = array();
  12.  
  13. // Sort bulky from regular
  14. foreach ( WC()->cart->get_cart() as $item ) {
  15. if ( $item['data']->needs_shipping() ) {
  16. if ( $item['data']->get_shipping_class() == 'free' ) {
  17. $bulky_items[] = $item;
  18. } else {
  19. $regular_items[] = $item;
  20. }
  21. }
  22. }
  23.  
  24. // Put inside packages
  25. if ( $bulky_items ) {
  26. $packages[] = array(
  27. 'ship_via' => array( 'flat_rate' ),
  28. 'contents' => $bulky_items,
  29. 'contents_cost' => array_sum( wp_list_pluck( $bulky_items, 'line_total' ) ),
  30. 'applied_coupons' => WC()->cart->applied_coupons,
  31. 'destination' => array(
  32. 'country' => WC()->customer->get_shipping_country(),
  33. 'state' => WC()->customer->get_shipping_state(),
  34. 'postcode' => WC()->customer->get_shipping_postcode(),
  35. 'city' => WC()->customer->get_shipping_city(),
  36. 'address' => WC()->customer->get_shipping_address(),
  37. 'address_2' => WC()->customer->get_shipping_address_2()
  38. )
  39. );
  40. }
  41. if ( $regular_items ) {
  42. $packages[] = array(
  43. 'contents' => $regular_items,
  44. 'contents_cost' => array_sum( wp_list_pluck( $regular_items, 'line_total' ) ),
  45. 'applied_coupons' => WC()->cart->applied_coupons,
  46. 'destination' => array(
  47. 'country' => WC()->customer->get_shipping_country(),
  48. 'state' => WC()->customer->get_shipping_state(),
  49. 'postcode' => WC()->customer->get_shipping_postcode(),
  50. 'city' => WC()->customer->get_shipping_city(),
  51. 'address' => WC()->customer->get_shipping_address(),
  52. 'address_2' => WC()->customer->get_shipping_address_2()
  53. )
  54. );
  55. }
  56.  
  57. return $packages;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement