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

2 thoughts on “Bulk Editing Product Attribute Variations in WooCommerce Without Crashing

  1. Recently faced an issue during variable products import, especially adding/merging variations.

    At least my goal was to have new variations added. I have been using WPAI Pro + Woo Import Add-On for years on a project, and the solution i came up with was to add a temporary parent variableproduct during import, and do a variations merge during the ‘pmxi_saved_post’ action. Until recently this worked like a charm: my function assembled ‘_product_attributes’, filled the values, fixed variation meta, and as an extra, created image-swatches for the color attribute of variations.

    Two weeks ago i did a new import for variation append, and i noticed, that ‘_product_attributes’, contains only the attribute base data of the attribute itself, but the value is empty.
    I suspected some mistake i made at coding of the product-merger, and started to recreate the content of the meta_data, and tried to load missing product images too, and i realized i have more colors listed, than product variations i have. About a week of bughunting without a clue, and not long ago i saw the light:
    I remembered having to delete obsolete products, also variations, and did some checks on the EAN codes, and their color, and found out, that deleting the obsolete variations did not remove the obsolete colors. At that point i remembered seeing tables like ‘wc_product_meta_lookup’, ‘wc_product_attributes_lookup’ . I started to search the blogs, and release notes, to find details about the migration to these tables, and the deprecation of the values of ‘_product_attributes’. But as to date, i have not found a HEADSUP like description how, and why this happens.

    If you have more uptodate knowledge about the usage of the new lookup tables, and how they replace the postmeta ‘_product_attributes’, i would be happy to read here about it.

    1. Thanks for sharing your story, I’ll see if I can cover this in one of the next articles or videos

Reply

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