How to Create Variable Virtual Downloadable Products Automatically When a New Image Is Uploaded – 2026

Last updated on August 17th, 2024 at 08:05 pm

For online stores that sell digital images, offering various sizes at different price points can enhance the customer experience and maximize revenue. This guide will show you how to automatically create variable virtual downloadable products with different pricing based on image size whenever a new image is uploaded to your WordPress media library.

Benefits of Automating Variable Product Creation

  • Efficiency: Streamline the product creation process.
  • Consistency: Ensure all products follow a standard format.
  • Revenue: Cater to different customer needs and budgets with tiered pricing.

Step 1: Add Code to Functions.php

To automatically create variable virtual downloadable products, you will need to add the following code to your theme’s functions.php file. If you don’t have a child theme, you can create one using our free child theme generator.

/*
 * Snippet: How to Create Variable Virtual Downloadable Products Automatically When a New Image Is Uploaded – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1373
* Tested with WooCommerce 10.7.0
* "Automatically Create Variable Virtual Downloadable Products"
*/ function wcsuccess_create_variable_virtual_product_on_image_upload($metadata, $attachment_id) { $attachment = get_post($attachment_id); $upload_dir = wp_upload_dir(); $file_path = $upload_dir['basedir'] . '/' . $attachment->guid; // Create a new product $product = new WC_Product_Variable(); $product->set_name($attachment->post_title); $product->set_status('publish'); $product->set_catalog_visibility('visible'); $product->set_description('Automatically created product for ' . $attachment->post_title); $product->set_virtual(true); $product->set_downloadable(true); $product->save(); // Define image sizes and prices $sizes = [ 'Small' => 5.00, 'Medium' => 10.00, 'Large' => 15.00 ]; // Add attributes and variations $attributes = new WC_Product_Attribute(); $attributes->set_name('Image Size'); $attributes->set_options(array_keys($sizes)); $attributes->set_visible(true); $attributes->set_variation(true); $product->set_attributes([$attributes]); $product->save(); foreach ($sizes as $size => $price) { $variation = new WC_Product_Variation(); $variation->set_parent_id($product->get_id()); $variation->set_attributes(['Image Size' => $size]); $variation->set_regular_price($price); $variation->set_virtual(true); $variation->set_downloadable(true); $variation->set_downloads([[ 'name' => $size . ' - ' . $attachment->post_title, 'file' => $file_path ]]); $variation->save(); } return $metadata; } add_filter('wp_generate_attachment_metadata', 'wcsuccess_create_variable_virtual_product_on_image_upload', 10, 2);

Step 2: Ensure Correct File Path and Permissions

Make sure the file path and permissions are correctly set to allow WooCommerce to access the uploaded images.

See also  How to Prevent Comment Spam Without a Plugin in WordPress - 2026

Step 3: Test the Functionality

Upload a new image via the WordPress media library to test if the code works correctly. The image should automatically create a variable virtual downloadable product with different sizes and corresponding prices.

Custom thumbnail sizes

You can integrate custom thumbnail sizes into the pricing of your variable virtual downloadable products to further enhance your offerings. By creating custom thumbnail sizes, you can assign different prices based on the resolution and quality of the images. This allows customers to choose the exact size that fits their needs and budget, creating a more personalized shopping experience. To learn how to create custom thumbnail sizes, refer to our detailed guide here. By combining these custom sizes with the automated product creation process, you can efficiently manage a diverse range of digital products in your WooCommerce store, maximizing both customer satisfaction and revenue.

See also  Automatic Coupons Based on Cart Total - 2026

Conclusion

By following the steps above, you can automate the creation of variable virtual downloadable products in WooCommerce whenever a new image is uploaded. This approach saves time, ensures consistency, and enhances the customer experience by offering different sizes and price points for digital images.

0 0 votes
Article Rating

Stay In Touch

Was this post helpful? Why not show your support and buy me a coffee?

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Scroll to Top
0
Would love your thoughts, please comment.x
()
x
×