-1

See comment in the code:
// Here I want to attach som text to checkout page under order review table for this specifik product id 7498 if quantity is 1 I have in the code bellow tried many things in javascript, but I wanna do It in PHP.

            add_action( 'woocommerce_before_cart', 'bbloomer_find_product_in_cart_alt' );  
            function bbloomer_find_product_in_cart_alt() {  
               $product_id_7498 = 7498;  
               $product_id_7475 = 7475;  
               $quantity1 = 1;  
               $quantity2 = 2;  
               $in_cart = false;  
               foreach( WC()-\>cart-\>get_cart() as $cart_item ) {  
                  $product_in_cart = $cart_item\['product_id'\];  
                  //$quantity_items = $cart_item\['quantity'\];  
                  //$item_quantity += $item-\>get_quantity();  
                  //echo $quantity_items;  
                  //$product_in_cart = $cart_item\['data'\];  
                  //echo $products_in_cart;  
                  //echo $cart_item\['product_id'\] . "\<br\>";  
                  //echo $cart_item\['quantity'\] . "\<br\>";  
                  //echo var_dump($products_in_cart) . "\<br\>";  
                  if ( $product_in_cart === $product_id_7498 ) {  
                      $in_cart = true;  
                      echo "Yes produkt 7498 finns i varukorgen . \<br\>";  
                      $product_quantity_7498 = $cart_item\['quantity'\];  
                      echo "Produkt 7498 / antal: " . $product_quantity_7498 . "\<br\>";  
                      if ($product_quantity_7498 === 1) {  
                          echo "Produkt 7498 antal är 1 . \<br\>";  
                                      // Here I want to attach som text to checkout page under order review table for this specifik product id 7498 if quantity is 1  
                      }  
                      if ($product_quantity_7498 === 2) {  
                          echo "Produkt 7498 antal är 2 . \<br\>";  
                                      // Here I want to attach som text to checkout page under order review table for this specifik product id 7498 if quantity is 2  
                      }  
                        
                  }  
                  if ( $product_in_cart === $product_id_7475 ) {  
                      $in_cart = true;  
                      echo "Yes produkt 7475 finns i varukorgen . \<br\>";  
                      $product_quantity_7475 = $cart_item\['quantity'\];  
                      echo "Produkt 7475 / antal: " . $product_quantity_7475 . "\<br\>";  
                  }  
               }  
            }
2
  • So what's the problem? Is this code not working? Commented yesterday
  • The code that you see is working. But read my question," Here I want to attach som text to checkout page under order review table for this specifik product id 7498 if quantity is 1". Commented yesterday

1 Answer 1

1

I think you may be misusing === here, and another place.

$product_quantity_7498 === 1

This won’t ever come up true if the value in the variable is any text string, including the text string ’1’. Try using == in place of ===. This kind of data is often stringly typed in WordPress. The == operator tries to compare things by value rather than they having the same data type and value.

Other than that, it’s debugger time.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.