title: Adding a hidden product to cart with applied coupon woocommerce/wordpress
body: <p>I have searched far and wide for a solution to add a free item (that I have hidden with woocommerce) to the cart when someone enters the hiddenproduct coupon I made. This is the code that I am using, it is a modified version of this:<a href="http://docs.woothemes.com/document/automatically-add-product-to-cart-on-visit/" rel="nofollow">http://docs.woothemes.com/document/automatically-add-product-to-cart-on-visit/</a>. The difference is instead of using the cart total to add it, I am trying to use the applied coupon.</p>
  
  <p>Here is my current code and it is not adding the product to the cart: </p>
  
  <pre><code>add_action( 'init', 'add_product_to_cart' );
  function add_product_to_cart() {
    if ( ! is_admin() ) {
      global $woocommerce;
      $product_id = 1211;
      $found = false;
      $coupon_id = 1212;
  
      if( $woocommerce-&gt;cart-&gt;applied_coupons == $coupon_id ) {
          //check if product already in cart
          if ( sizeof( $woocommerce-&gt;cart-&gt;get_cart() ) &gt; 0 ) {
        foreach ( $woocommerce-&gt;cart-&gt;get_cart() as $cart_item_key =&gt; $values ) {
                  $_product = $values['data'];
                  if ( $_product-&gt;id == $product_id )
                      $found = true;
              }
              // if product not found, add it
              if ( ! $found )
                  $woocommerce-&gt;cart-&gt;add_to_cart( $product_id );
          } else {
              // if no products in cart, add it
                  $woocommerce-&gt;cart-&gt;add_to_cart( $product_id );
              }
          }
      }
  }
  </code></pre>
  
  <p>I am pretty sure that the error is happening here '( $woocommerce->cart->applied_coupons == $coupon_id )' but I do not know the correct identifiers.</p>
  
  <p>This is in my functions.php </p>
  
  <p>Can anyone help me out? Thank you</p>