Bulk Editing Product Attribute Variations in WooCommerce Without Crashing

In a recent Business Bloomer Club Slack thread, a WooCommerce user needed to bulk edit product attributes across a large catalog.

Specifically, they wanted to modify only certain attributes, leaving others untouched, without relying on WP All Import due to timeout issues when dealing with a high volume of products.

This guide covers how to approach this type of bulk attribute modification using both database and code-based solutions while minimizing the risk of timeouts or errors.

Step 1: Understanding Attribute Storage in WooCommerce

WooCommerce stores product attribute data in the postmeta table, specifically under the _product_attributes meta key for each product. This data is stored as serialized data, making it trickier to edit directly because changing it improperly can corrupt the data format.

To locate product attribute data:

  1. Access the wp_postmeta table in your database.
  2. Find the post_id of the product you wish to edit.
  3. Look for the _product_attributes meta key, which contains serialized data, including fields like is_variation for each attribute.

Step 2: Bulk Update Serialized Data Using SQL Queries

For those comfortable with SQL, you can try using a REPLACE function in MySQL. However, because serialized data is highly sensitive to structure changes, test these queries on a staging site first to avoid corruption.

Example SQL query to toggle is_variation on certain attributes:

UPDATE wp_postmeta
SET meta_value = REPLACE(meta_value, 's:10:"is_variation";i:1;', 's:10:"is_variation";i:0;')
WHERE meta_key = '_product_attributes' AND post_id = [your_product_id];

Important: Modify only specific parts of the serialized string, and always test on a few records first. Direct SQL updates should only be attempted if you’re familiar with serialized data structures, as errors can break your product pages.

Step 3: Code-Based Solution for Selective Attribute Update

A safer approach is to use WooCommerce and WordPress hooks in PHP to loop through products and update only specific attributes. This method ensures that serialized data remains intact.

Here’s an example of how to do this:

function update_product_attributes_variations() {
    $args = array(
        'post_type' => 'product',
        'posts_per_page' => -1, // Adjust for testing if necessary
    );

    $products = get_posts( $args );

    foreach ( $products as $product_post ) {
        $product = wc_get_product( $product_post->ID );
        $attributes = $product->get_attributes();

        foreach ( $attributes as $attribute_name => $attribute ) {
            if ( $attribute_name !== 'brand' && $attribute_name !== 'strength' ) {
                $attribute->set_variation( false ); // Disable variation for non-targeted attributes
            }
        }

        $product->save();
    }
}
add_action( 'init', 'update_product_attributes_variations' );
  • Explanation: This code loops through all products and updates only attributes that aren’t named “brand” or “strength,” disabling the is_variation field for the rest. Run this code on a staging site to verify that it behaves as expected before deploying.

Step 4: Overcoming WP All Import Timeout Issues

If you prefer using WP All Import, try these tips to prevent timeout issues:

  1. Limit Imports to Specific Fields: Update only the attributes field rather than the entire product record to reduce processing time.
  2. Adjust Timeouts and Batches: Increase PHP execution time on your server, or configure WP All Import to process smaller batches.
  3. Disable Unnecessary Plugins: Temporarily disable plugins other than WooCommerce and WP All Import during the import to reduce server load.

Conclusion

Updating attributes across a WooCommerce product catalog can be complex, especially with serialized data. For safe results, try using a PHP function to loop through products and adjust attributes selectively. Alternatively, adjust WP All Import settings to prevent timeouts. Always test these changes on a staging site first to prevent accidental data corruption on live products.

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Reply

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