title: Woocommerce Free Downloads without checkout
body: <p>I'm trying to make free downloads easy to download, without any checkout or form to complete.
  I just found this code on Github, but I don't know how to add it and get it working.</p>
  
  <pre><code>function direct_free_downloads_button( $button )
  {
      global $product;
  
      if( $product-&gt;is_downloadable() AND $product-&gt;get_price() == 0 )
      {
          $files = $product-&gt;get_files();
          $files = array_keys($files);
  
          $download_url = home_url('?download_file='.$product-&gt;id.'&amp;key='.$files[0].'&amp;free=1' );
  
          $button = sprintf( '&lt;a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" data-quantity="%s" class="button %s product_type_%s"&gt;%s&lt;/a&gt;',
              esc_url( $download_url  ),
              esc_attr( $product-&gt;id ),
              esc_attr( $product-&gt;get_sku() ),
              esc_attr( isset( $quantity ) ? $quantity : 1 ),
              $product-&gt;is_purchasable() &amp;&amp; $product-&gt;is_in_stock() ? '' : '',
              esc_attr( $product-&gt;product_type ),
              esc_html( 'Download' )
          );
      }
      return $button;
  }
  add_filter('woocommerce_loop_add_to_cart_link', 'direct_free_downloads_button', 100);
  
  
  /**
   * Handles downloading of free Downloadable products
   * @return [type] [description]
   */
  function download_free_product_file()
  {
      $product_id    = absint( $_GET['download_file'] );
      $_product      = wc_get_product( $product_id );
  
      if( $_product-&gt;get_price() == 0 ) {
          WC_Download_Handler::download( $_product-&gt;get_file_download_path( filter_var($_GET['key'], FILTER_SANITIZE_STRING)  ), $product_id );
      }
  }
  
  if ( isset( $_GET['download_file'] ) &amp;&amp; isset( $_GET['key'] ) &amp;&amp; $_GET['free'] ) {
      add_action( 'init', 'download_free_product_file' );
  }
  </code></pre>