Bulk updating Autoship product options

By default, Autoship is enabled on a per-product basis for simple and variable WooCommerce products.  

This allows store owners to easily manage which products are available to customers for Autoship.

However, most bulk operations for WC Autoship can be easily performed by a database expert who is familiar with the Wordpress/WooCommerce database structure.

Product options

All WC Autoship product options are stored alongside the standard WooCommerce product settings.

Each WooCommerce product is stored as a "post" with a "post type" value of "product". 

SELECT * FROM wp_posts WHERE wp_posts.post_type = 'product';

Related product options for a product are stored as "post meta" following the standard WooCommerce format.

SELECT wp_postmeta.meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = '_wc_autoship_price';

The available product meta for WC Autoship are listed below:

wp_postmeta.meta_key wp_postmeta.meta_value Description
_wc_autoship_enable_autoship [yes/no] Enable Autoship
_wc_autoship_price [0.00] Autoship Price
_wc_autoship_min_frequency [7 - 365] Minimum Autoship Frequency
_wc_autoship_max_frequency [7 - 365] Maximum Autoship Frequency
_wc_autoship_default_frequency [7 - 365] Default Autoship Frequency

Example: Enable Autoship for all simple products

Bulk updating is a careful process that should be handled by an expert to prevent data loss and data corruption. 

Important: Step 1 for all bulk updates is to make a complete backup of your data!

The process to enable Autoship for all of your products is outlined below:

  1. Make a complete backup of your database.
  2. Delete existing Autoship product meta data.
  3. Insert new Autoship product meta data.
  4. Test your updates.

In this example, we will enable Autoship on all simple products with the following options:

  • Minimum Autoship Frequency: 7 days
  • Maximum Autoship Frequency: 365 days

Step 1: Backup your database

Follow the official documentation in the  Wordpress Codex to back up your database.

Step 2: Delete Autoship product meta data

WooCommerce product meta data must be cleared out so that the same meta key is not entered twice. This can cause data corruption if not handled properly. Execute the three queries below to clear out the selected meta data for Autoship products:

/* delete Enable Autoship option */
DELETE FROM wp_postmeta WHERE meta_key = '_wc_autoship_enable_autoship' AND post_id IN(SELECT ID FROM wp_posts WHERE post_type = 'product');

/* delete Min Autoship Frequency option */
DELETE FROM wp_postmeta WHERE meta_key = '_wc_autoship_min_frequency' AND post_id IN(SELECT ID FROM wp_posts WHERE post_type = 'product');

/* delete Max Autoship Frequency option */
DELETE FROM wp_postmeta WHERE meta_key = '_wc_autoship_max_frequency' AND post_id IN(SELECT ID FROM wp_posts WHERE post_type = 'product');

Step 3: Insert Autoship product meta data

/* insert Enable Autoship option */
INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT ID, '_wc_autoship_enable_autoship', 'yes'
FROM wp_posts WHERE post_type = 'product';

/* insert Min Autoship Frequency option (7 days) */
INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT ID, '_wc_autoship_min_frequency', '7'
FROM wp_posts WHERE post_type = 'product';

/* insert Max Autoship Frequency option (365 days) */
INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT ID, '_wc_autoship_max_frequency', '365'
FROM wp_posts WHERE post_type = 'product';

Step 4: Test your updates

Edit a WooCommerce product in your WP Admin. In the Autoship data section, you should see the following options set:

  • Enable Autoship: checked
  • Min Autoship Frequency: 7
  • Max Autoship Frequency: 365

View the product page for this product. You should be able to select an Autoship option within the range of 7 to 365 days.

Still need help? Contact Us Contact Us