Advertisement
nshelper

Untitled

Aug 4th, 2022
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1.  
  2.         foreach (WC()->cart->get_cart_contents() as $cart_id => $cart_item) {
  3.            
  4.             do_action( 'woocommerce/cart_loop/start', $cart_item );
  5.  
  6.             if (!$this->is_cart_item_valid($cart_item)) {
  7.                 do_action( 'woocommerce/cart_loop/end', $item );
  8.                 continue;
  9.             }
  10.  
  11.             if (is_a($cart_item['data'], 'WC_Product_Variation')) {
  12.  
  13.                 $parent_prod  = wc_get_product($cart_item['data']->get_parent_id());
  14.                 $product_cats = $parent_prod->get_category_ids();
  15.  
  16.             } else {
  17.                 $product_cats = $cart_item['data']->get_category_ids();
  18.             }
  19.  
  20.             $intersect = array_intersect($product_cats, $condition_cats);
  21.  
  22.             if (!empty($intersect)) {
  23.                 $cart_quantity += (int) $cart_item['quantity'];
  24.             }
  25.            
  26.             do_action( 'woocommerce/cart_loop/end', $cart_item );
  27.  
  28.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement