php - Check the product category/id before add it to the cart (Woocommerce) -


im looking make function must that, example:

i have 10 categories, 3 of them special, name are: "alpha", "bravo" , "charlie"

in function must have array category id of category "alpha", "bravo" , "charlie"

  1. when user click "add cart" function must check if cart empty, if cart empty function must reset global variable named $restricted_item_cart
  2. after function, must check, if product category of item want add cart contain array have place category "alpha", "bravo" , "charlie"
  3. if item category contain in array, function must add product id global variable $restricted_item_cart

can me please?

new edit (new code, im not pro php coder, can tell me if right?):

function my_add_woo_cat_classes($classes) { 

 

global $restricted_cart_items ;     if ( is_null( $cart )){             $restricted_cart_items=array();     }    global $post; $terms = get_the_terms( $post->id, 'product_cat' );     foreach ($terms $term) {             $product_cat_id = $term->term_id;             break;     }  $restricted_category= array(11,22);  if (in_array( $product_cat_id, $restricted_category)){     $current_product= $product->id;     $restricted_cart_items=array($current_product); }  return $restricted_cart_items; } 


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -