Guest User

Untitled

a guest
Dec 10th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. /**
  2. * Cart collaterals hook.
  3. *
  4. * @hooked woocommerce_cross_sell_display
  5. * @hooked woocommerce_cart_totals - 10
  6. */
  7. $categories = array( 39 );
  8.  
  9. foreach ( WC()->cart->get_cart() as $cart_item ) {
  10. if ( has_term( $categories, 'product_cat', $cart_item['product_id'] ) ) {
  11. $found = true; // Set to true
  12. break; // Stop the loop
  13. }
  14. }
  15.  
  16. if( $found ) {
  17. echo 'Category with ID = 39';
  18. }
  19. else if ($found != $cart_item['category_ids']) {
  20. echo "Category with ID = 39 and other ID('s)";
  21. }
  22. else {
  23. "Category with ID != 39";
  24. }
  25.  
  26. ["category_ids"]=>
  27. array(1) {
  28. [0]=>
  29. int(39)
  30. }
  31. /// another stuff in the array
  32.  
  33. ["category_ids"]=>
  34. array(2) {
  35. [0]=>
  36. int(32)
  37. [1]=>
  38. int(33)
  39. }
Add Comment
Please, Sign In to add comment