title: Regenerating WooCommerce Download Permissions on older orders
body: <p>I am trying to add some download permissions to all previous orders via a script to do them in batch. The script seems to work fine expect for one thing. Here is the script…</p>
  
  <pre><code>function update_download_permissions(){
  
    $orders = get_posts( array(
      'post_type'      =&gt; 'shop_order',
      'post_status'    =&gt; 'wc-completed',
      'posts_per_page' =&gt; -1
    ) );
  
    foreach ( $orders as $order ) {
      wc_downloadable_product_permissions( $order-&gt;ID, true );
    }
  
  }
  </code></pre>
  
  <p>The problem is the wc_downloadable_product_permissions function is producing duplicate entries in the wp_woocommerce_downloadable_product_permissions table.</p>
  
  <p>I tried to set the second argument to false (the default) but that resulted in no permissions being created.</p>
  
  <p>Does anybody have any ideas as to why duplicate download permissions are being set?</p>
  
  <p>Cheers!</p>