title: Woocommerce (Wordpress plugin) programatically generated product isn't accessible to guest
body: <p>I'm using WordPress 3.9.1 and the latest version of WooCommerce (2.1.10) and I'm trying to create a "Pay your invoice" page where people put their invoice number and amount and they go directly to the checkout page.</p>
  
  <p>The way I'm doing it now:</p>
  
  <p>I have a page with a form where people put in the amount:</p>
  
  <pre><code>&lt;form action="#" onsubmit="location.href = 'http://protexfs.co/invoicepage/?date=' + this.elements.date.value; return false;"&gt;
  &lt;input type="text" name="date"&gt;
  &lt;input type="submit" value="Go"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The submit button leads to a page that automatically generates a Woocommerce product for the same amount and adds it to the cart and automatically redirects to the checkout page (I use the Insert PHP plugin for all my PHP needs):</p>
  
  <pre><code>[insert_php]
  //empty cart
  global $woocommerce;
  $woocommerce-&gt;cart-&gt;empty_cart();
  // Remove default cart message
  $woocommerce-&gt;clear_messages();
  
  //price
  $invoiceprice = filter_input(INPUT_GET,"date",FILTER_SANITIZE_STRING);
  
  //Generate title
  $timestampedtitle = "Date: ".date("d/m/Y")." Amount: £".$invoiceprice;
  
  //Generate message
  $message = date_timestamp_get(date_create())." Date: ".date('m/d/Y h:i:s a', time())." Invoice amount: £".$invoiceprice;
  
  $post = array(
  'post_author' =&gt; '2',
  'post_status' =&gt; "publish",
  'post_title' =&gt; $timestampedtitle,
  'post_content' =&gt; $message,
  'post_parent' =&gt; '',
  'post_type' =&gt; "product",
  //'post_status' =&gt; 'private',
  );
  
  //Create post
  $post_id = wp_insert_post( $post, $wp_error );
  if($post_id){
  $attach_id = get_post_meta($product-&gt;parent_id, "_thumbnail_id", true);
  add_post_meta($post_id, '_thumbnail_id', $attach_id);
  }
  wp_set_object_terms($post_id, 'simple', 'product_type');
  update_post_meta( $post_id, '_visibility', 'search' );
  update_post_meta( $post_id, '_stock_status', 'instock');
  update_post_meta( $post_id, '_virtual', 'yes');
  update_post_meta( $post_id, '_regular_price', $invoiceprice );
  update_post_meta( $post_id, '_sale_price', $invoiceprice );
  update_post_meta( $post_id, '_purchase_note', "" );
  update_post_meta( $post_id, '_featured', "no" );
  update_post_meta( $post_id, '_weight', "" );
  update_post_meta( $post_id, '_length', "" );
  update_post_meta( $post_id, '_width', "" );
  update_post_meta( $post_id, '_height', "" );
  update_post_meta($post_id, '_sku', "");
  update_post_meta( $post_id, '_product_attributes', array());
  update_post_meta( $post_id, '_sale_price_dates_from', "" );
  update_post_meta( $post_id, '_sale_price_dates_to', "" );
  update_post_meta( $post_id, '_price', $invoiceprice );
  update_post_meta( $post_id, '_sold_individually', "" );
  update_post_meta( $post_id, '_manage_stock', "no" );
  update_post_meta( $post_id, '_backorders', "no" );
  update_post_meta( $post_id, '_stock', "" );
  update_post_meta( $post_id, '_et_pb_page_layout', 'et_full_width_page' );
  
  if( $woocommerce-&gt;cart ) {
       $woocommerce-&gt;cart-&gt;add_to_cart( $post_id, $quantity=1 );}
  
  $url = $woocommerce-&gt;cart-&gt;get_checkout_url();
  header("Location: $url");
  [/insert_php]
  </code></pre>
  
  <p>This seems to work perfectly as long as I am logged in. However, if the user is not logged in, the product still gets generated but can't be added to the cart, showing the following message:"Sorry, this product cannot be purchased." (which ruins the whole thing).</p>
  
  <p>The weird thing is that any other product I create through the WooCommerce interface can be accessed by the guests (so if I have a publicly available product and I programatically change its price and add it to the cart, it works -> but that creates problems when 2 people click the button at the same time).</p>
  
  <p>Before you ask, I have enabled Guest checkout in the WooCommerce setting.</p>
  
  <p>Any ideas on how to fix this? (Or possibly a completely different way to achieve my goal?)</p>
  
  <p>Vlad</p>