Update Downloadable Product’s Expiration Date in WooCommere

sql query
  1. Blogging for Benjamin Competition
  2. Why I'm Grateful to Work on the Web
  3. 24 Pull Requests
  4. Update Downloadable Product's Expiration Date in WooCommere
  5. Get Lost in the Flow and Work for More Than a Salary
  6. Why A Plugin's Popularity Matters
  7. Why You Should (Or Shouldn't) Use Premium Plugins
  8. WooCommerce Terms & Conditions
  9. Only Ship to Continental United States with WooCommerce
  10. Just Talk
  11. Why I Love Jetpack
  12. Making Jetpack Better
  13. Remove Billing Address for Free Virtual Orders in WooCommerce
  14. Notify Admin of Customer Address Change in WooCommerce
  15. Open Your Self Up To New Possibilities
  16. 2013 Resolutions Review
  17. Create a Community
  18. Tips for Starting a Community
  19. The Intent of Goals
  20. Create The Ultimate Invoicing System Using WooCommerce
  21. Change From Address in Ninja Forms
  22. Work With People Who Inspire You
  23. Contact Form 7 & MailPoet Integration
  24. Monotasking
  25. Giving Back to The Community
  26. Adding Fuctionality to Lean Plugins
  27. Choose Stripe For a Payment Gateway
  28. A Dip Into Entrepreneurship
  29. Reward Yourself
  30. Blogging for Benjamin Plugin
  31. Blogging for Benjamin Wrap Up

WooCommerce has a pretty fantastic admin user interface. There's just enough tabs to only show you the data you need to see and have the rest of the data be easily accessible. If you're just editing one product it should be easy to change something as simple as the “download expiration” field. But what happens if you need to bulk edit products? Could you use the WordPress bulk editor?

The default WordPress bulk editor is great for a handful of products. But what if your company has some sort of policy change? Like one that changes how long all of your links are valid. If that's the case you could easily be editing all of the products in your store. That's where it helps to know a little code and just update the database directly.

SQL to the Rescue

table prefix

Table prefix in wp-config.php

I wrote a short little SQL statement that you can execute through phpMyAdmin. It will go through all of your products and change their download expiration date fields. This will affect all future purchases of those products. The snippet automatically changes the expiration date to 7 but you can change that 7 to any number you want. Just make sure to update the wp_postmeta table with your own table prefix set in your wp-config.php file.


UPDATE wp_postmeta
SET meta_value='7'
WHERE meta_key='_download_expiry'

What About Past Orders?

If you want to change the download expiration date for products that are already purchased you'll have to do some additional work in the database. You'll have to update the access_expires in the wp_woocommerce_downloadable_product_permissions table.

Blogging for Benjamin

This is the fourth post for the Blogging for Benjamin contest. If you have certain topics that you'd like for me to discuss please list them in the comments. I'll have all of December to fill up with blog posts. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.