How to Filter WooCommerce Variations by Attributes When Editing Products

  • January 14, 2026
  • Deepak Gupta
  • 5 min read

Advanced Admin UX Guide by a Plugin Developer & Full Stack Developer

Managing variable products in WooCommerce can quickly become frustrating—especially when a product has dozens or even hundreds of variations. As a WooCommerce Developer, I’ve seen store owners and admins struggle to find the exact variation they want to edit.

For example, imagine a product with:

  • 3 attributes
  • 10 values per attribute

That’s 3 × 3 × 10 = 90 variations inside the WooCommerce admin panel. Scrolling endlessly through variations is inefficient and error-prone. Many of my clients raised this issue, and rightly so—the default WooCommerce UI is not optimized for this scenario.

So, can we improve it?

Absolutely.

In this guide, Deepak Gupta Developer shows you how to filter WooCommerce variations by attributes inside the admin panel using AJAX, improving usability without breaking WooCommerce core behavior. This solution is ideal for advanced stores and custom admin workflows.


Why WooCommerce Needs Variation Filters in Admin

From a WordPress Developer and Plugin Developer perspective, WooCommerce variations are stored efficiently—but the admin UI doesn’t provide filtering tools by default.

This leads to:

  • Slower product editing
  • Higher chance of editing the wrong variation
  • Poor admin experience for large catalogs

As a Full Stack Developer, improving internal tools is just as important as frontend UX.


Strategy Overview

We’ll build:

  1. Attribute-based <select> filters in the admin
  2. AJAX-powered variation loading
  3. Server-side variation filtering using meta_query

This approach:

  • Does not modify WooCommerce core
  • Uses official hooks and AJAX endpoints
  • Scales well for large stores

Step 1: Display Attribute Filters Before Variations

WooCommerce provides the action hook:

woocommerce_variable_product_before_variations

This hook fires right before the variations list, making it the perfect place to insert filters.

PHP Code: Add Attribute Filters in Admin
add_action( 'woocommerce_variable_product_before_variations', 'dg_variation_filters' );
function dg_variation_filters() {

	global $post;

	$product = wc_get_product( $post->ID );
	$attributes = $product->get_attributes();

	if( ! $attributes ) {
		return;
	}
	?>
	<div class="toolbar toolbar-variations-filters">
		<strong>Filter variations by:</strong>
		<?php foreach( $attributes as $attribute ) {

			if( ! $attribute['variation'] || empty( $attribute['options'] ) ) {
				continue;
			}
			?>
			<select data-attr_name="<?php echo esc_attr( $attribute['name'] ); ?>">
				<option value="">
					Any <?php echo wc_attribute_label( $attribute['name'] ); ?>
				</option>

				<?php
				if( strpos( $attribute['name'], 'pa_' ) === 0 ) {

					$terms = get_terms([
						'taxonomy'   => $attribute['name'],
						'hide_empty' => false,
						'include'    => $attribute['options'],
					]);

					foreach ( $terms as $term ) {
						echo '<option value="' . esc_attr( $term->slug ) . '">' . esc_html( $term->name ) . '</option>';
					}

				} else {

					foreach ( $attribute['options'] as $option ) {
						echo '<option value="' . esc_attr( $option ) . '">' . esc_html( $option ) . '</option>';
					}
				}
				?>
			</select>
		<?php } ?>
	</div>
	<?php
}

💡 As a Plugin Developer, notice we didn’t use a <form>—it’s unnecessary for AJAX-based filtering.


Step 2: Send AJAX Request When Filters Change

Now we need to reload variations dynamically when filters change. As a Mern Stack Developer, I treat WooCommerce admin AJAX the same way I treat API-driven dashboards—clean, fast, and predictable.

JavaScript (jQuery): Send Filter Request
$( '.toolbar-variations-filters select' ).change( function() {

	const container = $('#woocommerce-product-data'),
		  wrapper = $('#variable_product_options').find('.woocommerce_variations'),
		  attributes = {};

	$('.toolbar-variations-filters select').each(function() {
		attributes[$(this).data('attr_name')] = $(this).val();
	});

	container.block({
		message: null,
		overlayCSS: { background: '#fff', opacity: 0.6 },
	});

	$.ajax({
		url: woocommerce_admin_meta_boxes_variations.ajax_url,
		type: 'POST',
		data: {
			action: 'dg_load_variations',
			security: woocommerce_admin_meta_boxes_variations.load_variations_nonce,
			product_id: woocommerce_admin_meta_boxes_variations.post_id,
			attributes: attributes
		},
		success: function(response) {
			wrapper.html(response).attr('data-page', 1);
			container.unblock();
		}
	});
});

📌 Tip from a Full Stack Developer: Always add wc-admin-variation-meta-boxes as a script dependency when enqueueing this file.


Step 3: Process the AJAX Request in PHP

Now we filter variations server-side using meta_query. Unlike products, variations are filtered by meta, not tax queries.

PHP Code: Load Filtered Variations
add_action( 'wp_ajax_dg_load_variations', 'dg_load_variations' );
function dg_load_variations() {

	check_ajax_referer( 'load-variations', 'security' );

	if ( ! current_user_can( 'edit_products' ) || empty( $_POST['product_id'] ) ) {
		wp_die();
	}

	$product_id = absint( $_POST['product_id'] );

	$args = [
		'post_type'      => 'product_variation',
		'post_parent'    => $product_id,
		'posts_per_page' => -1,
		'meta_query'     => [],
	];

	foreach ( $_POST['attributes'] as $name => $value ) {
		if ( empty( $value ) ) continue;

		$args['meta_query'][] = [
			'key'   => 'attribute_' . sanitize_text_field( $name ),
			'value' => sanitize_text_field( $value ),
		];
	}

	$variations = get_posts( $args );

	foreach ( $variations as $variation ) {
		$variation_object = wc_get_product( $variation->ID );
		include WC()->plugin_path() . '/includes/admin/meta-boxes/views/html-variation-admin.php';
	}

	wp_die();
}

Result: Clean & Usable Variation Filtering

You now have:

  • Attribute-based filters
  • AJAX-powered variation loading
  • Zero WooCommerce core edits

This dramatically improves admin productivity—especially for stores with complex catalogs.


Why This Matters for Large WooCommerce Stores

As a WooCommerce Developer and Plugin Developer, I recommend this approach for:

  • Fashion & apparel stores
  • Configurable product catalogs
  • B2B WooCommerce platforms

When combined with custom admin UX improvements, this turns WooCommerce into a scalable product management system.


Final Thoughts

Improving WooCommerce admin usability is often overlooked—but it has a direct impact on operational efficiency. With a bit of smart hook usage and AJAX, you can transform how variations are managed.

Built with the mindset of a WordPress Developer, powered by a Mern Stack Developer, and executed as a Full Stack Developer, this solution fits seamlessly into professional WooCommerce builds.

Leave a Reply

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