title: Woocommerce - can't add to cart as a guest using Quick Order One Page Shop?
body: <p>Using the plugin @ <a href="http://products.solvercircle.com/woocommerce-one-page-quick-shop/quick-shop/" rel="nofollow">http://products.solvercircle.com/woocommerce-one-page-quick-shop/quick-shop/</a></p>
  
  <p>It seems like if I'm logged in as a regular user in the admin, I can add items to the cart fine. If I add to cart as a guest however it does the ajax request and returns a '1' but the item is never added to the cart.</p>
  
  <p>Does anyone know why it might be so? The other 2 plugins I have on the site I deactivated and can still reproduce this, so I believe this is a bug in this plugin.</p>
  
  <p><strong>EDIT</strong>: I confirmed that 'guests can checkout' settings box is applied, so that doesn't seem to be it.</p>
  
  <p><strong>EDIT #2</strong>: Here's the add to cart fn:</p>
  
  <pre><code>  function wqo_add_prod(pid,vid){
      var qty= jQuery('#product_qty_'+vid).val();
      if(qty==0){
        jQuery('#wqo_alert_info').text('Out of Stock');
        jQuery('#wqo_alert_info').show()
        setTimeout(function(){jQuery('#wqo_alert_info').hide()}, 1500);      
        return false;
      }
      if(vid==0){
        qty= jQuery('#product_qty_'+pid).val();
      }
  
      var ajax_url = 'http://DOMAIN.com/wp-admin/admin-ajax.php';
          jQuery.ajax({
            type: "POST",
            url:ajax_url,
                data : {
                    'action':          'wqo_addtocart',
                    'wqo_prod_id':     pid,
                    'wqo_prod_var_id': vid,
                    'wqo_prod_qty':    qty
            },
            success: function(response){            
              if(response==1){
                jQuery('#wqo_alert_info').text('Added to your cart');
              }else{
                jQuery('#wqo_alert_info').text(response);
              }
  
              jQuery.ajax({
                type: "POST",
                url:ajax_url,
                data : {'action': 'wqo_cart_amount'},
                success: function(data){             
                  jQuery('#wqo_cart_price').html(data);
                }
              });
  
               jQuery('#wqo_alert_info').show()
               setTimeout(function(){jQuery('#wqo_alert_info').hide()}, 2000);          
            }
          });
    }
  </code></pre>
  
  <p><strong>EDIT #3:</strong> Source for the php callback</p>
  
  <pre><code>function wqo_addtocart() {
    global $woocommerce;
    $vid=$_POST['wqo_prod_var_id'];
    $pid=$_POST['wqo_prod_id'];
    $vid=$_POST['wqo_prod_var_id'];
    $pqty=$_POST['wqo_prod_qty'];
  
    if($vid==0){
      $product = WC_Product_Factory::get_product($pid);    
    }else{
      $product = WC_Product_Factory::get_product($vid);    
    }
    $stock=$product-&gt;get_stock_quantity();
    $availability = $product-&gt;get_availability();
  
    if($availability['class']=='out-of-stock'){
      echo 'Out of stock';
      exit;
    }
  
    if($stock!=''){
          foreach($woocommerce-&gt;cart-&gt;cart_contents as $cart_item_key =&gt; $values ) {
          $c_item_id='';
          $c_stock='';
          if($values['variation_id']!=''){
            $c_item_id=$values['variation_id'];
          }else{
            $c_item_id=$values['product_id'];
          }
          $c_stock=$values['quantity']+$pqty;
  
          if($vid==0 &amp;&amp; $pid==$c_item_id &amp;&amp; $c_stock&gt;$stock){
            $product = WC_Product_Factory::get_product($pid);
            echo 'You have cross the stock limit';
            exit;
          }else if($vid==$c_item_id &amp;&amp; $c_stock&gt;$stock){
            $product = WC_Product_Factory::get_product($vid);
            echo 'You have cross the stock limit';
            exit;
          }        
         }    
    }
  
    if($vid==0){
      $z=$woocommerce-&gt;cart-&gt;add_to_cart($pid,$pqty,null, null, null );
    }else{    
      $z=$woocommerce-&gt;cart-&gt;add_to_cart($pid, $pqty, $vid, $product-&gt;get_variation_attributes(),null);
    }
    echo '1';
  
    exit;
  }
  </code></pre>
  
  <p>Registers at the bottom of <strong>woo-quick-order/includes/wqo-view.php</strong> ( also where the above fns are stolen from )</p>
  
  <pre><code>675 add_action( 'wp_ajax_nopriv_wqo_addtocart','wqo_addtocart' );
  676 add_action( 'wp_ajax_wqo_addtocart', 'wqo_addtocart' );
  </code></pre>
  
  <p><strong>EDIT #4</strong>: I think it's a session issue. In the first ajax call which calls <code>wqo_addtocart</code> if I do:</p>
  
  <p><code>var_dump($woocommerce-&gt;cart-&gt;cart_contents);</code></p>
  
  <p>It returns the array and the main key is the hash that <code>$z</code> returns.</p>
  
  <p>On the second ajax request however, this is lost:</p>
  
  <pre><code> 59 function wqo_cart_amount(){
   60   global $woocommerce;
   61   var_dump($woocommerce-&gt;cart-&gt;cart_contents);
   62   echo $woocommerce-&gt;cart-&gt;get_cart_total();
   63   exit;
   64 }
  </code></pre>
  
  <p>This returns an empty array. So in between the first and second ajax requests it gets lost.</p>