WooCommerce: Allow CSV Product Export By Tag

Ok, this is a little hacky and pretty manual, but it happened to me in the past that the inbuilt WooCommerce CSV product export was just not enough.

In other words, the default product export that you can find by clicking the “Export” button on the “Products” WordPress Dashboard screen, gives you the option to export all products to a CSV. You can also refine the list by product type and product category, so that you can export specific products only.

What’s missing there is a “product tag” filter, so this workaround will let you do just that – define a product tag slug in the snippet below, and your export list will be automatically filtered by that.

Of course, you could find a dynamic way of doing that, but for now we’ll keep this manual and hardcoded into the PHP function. Enjoy!

Unfortunately you can’t filter products by product tag before exporting them to CSV. Let’s find a little hack to do that!

PHP Snippet: Filter CSV Product Export By Product Tag @ WordPress Dashboard

/**
 * @snippet       Filter by Tag @ WooCommerce Product Export
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 7
 * @community     https://businessbloomer.com/club/
 */

add_filter( 'woocommerce_product_export_product_query_args', 'bbloomer_add_search_term_to_woocommerce_export' );

function bbloomer_add_search_term_to_woocommerce_export( $args ) {
	$args['tag'] = array( 'soft', 'tall' );
	return $args;
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

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

4 thoughts on “WooCommerce: Allow CSV Product Export By Tag

  1. Hi I have inserted the code suggested via code snippets plugin but nothing is changing – I still can’t filter by tag. Any idea why?

    Thank you

    Alex

    1. Did you put the correct tag slugs inside the array?

  2. Does the WooCommerce plugin offer any built-in features or extensions specifically designed for importing CSV product data based on tags?

    1. For importing, they only need a matching SKU. So nothing is stopping you by creating a CSV file with products of the same tag, and importing them into WooCommerce. Does that make sense?

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

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