Advertisement
nshelper

Untitled

Feb 3rd, 2025
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. <?php
  2. /**
  3. * Contains code for cart util class.
  4. *
  5. * @package Boxtal\BoxtalConnectWoocommerce\Util
  6. */
  7.  
  8. namespace Boxtal\BoxtalConnectWoocommerce\Util;
  9.  
  10. /**
  11. * Cart util class.
  12. *
  13. * Helper to manage cart.
  14. */
  15. class Cart_Util {
  16.  
  17. /**
  18. * Get cart weight.
  19. *
  20. * @return float
  21. */
  22. public static function get_weight() {
  23. $weight = 0;
  24. foreach ( WC()->cart->get_cart() as $item_id => $item ) {
  25. do_action( 'woocommerce/cart_loop/start', $item );
  26. if ( $item['data']->needs_shipping() ) {
  27. $variation_id = $item['variation_id'];
  28. $product_id = ( '0' !== $variation_id && 0 !== $variation_id ) ? $variation_id : $item['product_id'];
  29. $product_weight = Product_Util::get_product_weight( $product_id );
  30. if ( false === $product_weight ) {
  31. $product_weight = 0;
  32. }
  33. $weight += $product_weight * $item['quantity'];
  34. }
  35. do_action( 'woocommerce/cart_loop/end', $item );
  36. }
  37. return $weight;
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement