How do I bulk generate/grant download permissions on WooCommerce?

I am in a situation. I have a downloadable product, with over 3500 customers buying it so far. While updating the downloadable product, apparently I messed up and some how removed access to the current 3500+ clients resulting in many confused emails. The customers are still shown as buying the digital product in their account purchases.

So that brings me to desperately ask, how do I bulk generate/grant download permissions on WooCommerce to the customers that have already bought my downloadable product?

Read More

I’m thinking about a SQL query, but not exactly sure what I would need to move and to where? What makes it even more difficult is I only need the permissions to be granted to customers of the specific product!

Related posts

3 comments

  1. I came up with the following solution. You can place this code to functions.php, open any page in backend or frontend (to run functions.php) and then comment or delete this code. It will not affect orders which already have download permissions.

    add_action('init','my_activate_download_permissions');
    function my_activate_download_permissions() {
    
    $orders = get_posts( array(
        'post_type'      => 'shop_order',
        'post_status'    => 'wc-completed',
        'posts_per_page' => -1
    ) );
    
    foreach ( $orders as $order ) {
        wc_downloadable_product_permissions( $order->ID, false );
    }}
    
  2. @Tyree B. Hope you have resolved the issue, if yes then please share here else you can follow below solution:

    1. Loop through your all users and get their order (order no.) and add the new downloadable product in the existing order using wc_add_order_item woocommerce function (You will also need to add product meta like quantity, priduct id etc.)

    2. Loop through all customers and create a new order (gift order using code) for each customer and add product to the order. As per woocommerce rule/functionality automatically all user can download product from their my-account under download link.

    Hopes it will help you.

Comments are closed.