title: Woocommerce: Sorry, this product cannot be purchased
body: <p>I made a custom template to work with woocommerce (I have overwritten the existing templates by copying the folder to my theme and renaming it). I added a button on this page that should add the products to the cart using the following link:</p>
  
  <pre><code>&lt;a class="add-to-cart" href="?add-to-cart=&lt;?php echo get_the_ID(); ?&gt;"&gt;&lt;?php _e('Add to cart'); ?&gt;&lt;/a&gt;
  </code></pre>
  
  <p>However, when I go to my cart, I get the following message:</p>
  
  <pre><code>Sorry, this product cannot be purchased.
  </code></pre>
  
  <p>The products are of the type 'simple product' and they are added programmatically from an excel file. They are created in the following way:</p>
  
  <pre><code>public function handleAutomateRequest() 
  {
      $time = time();
  
      for($_SESSION['records_processed']; $_SESSION['records_processed'] &lt; $_SESSION['record_count']; $_SESSION['records_processed']++)
      {
          $row = $this-&gt;create_row_object($_SESSION['records'][$_SESSION['records_processed']]);
          $post = $this-&gt;get_post($row);
  
          $product = array();
          $product['ID'] = !is_null($post) ? $post-&gt;id : '';
          $product['post_name'] = $row-&gt;slug;
          $product['post_title'] = $row-&gt;title;
          $product['post_content'] = '';
          $product['post_type'] = 'product';
          $product['post_status'] = 'publish';
          $product['post_date'] = $row-&gt;date;
          $product['post_date_gmt'] = $row-&gt;date_gmt;
  
          if($row-&gt;title != '') {
              $post_id = wp_insert_post($product);
              wp_set_object_terms($post_id, array($row-&gt;brand), 'product_cat');
  
              $this-&gt;add_product_meta($post_id, $row);
  
              update_post_meta($post_id, '_sku', '#' . $post_id);
              update_post_meta($post_id, '_sale_price', $row-&gt;price);
              update_post_meta($post_id, '_regular_price', $row-&gt;price);
          }
  
          if(time() &gt; $time + 10) 
              break;
      }
  
      echo $_SESSION['records_processed'] != $_SESSION['record_count'] ? $_SESSION['records_processed'] . ' / ' . $_SESSION['record_count'] : 'DONE';
      die();
  }
  </code></pre>
  
  <p>I have absolutely no idea what may be causing the error. After looking around the internet, I have become none the wiser. Any idea on what the problem might be?</p>