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        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @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

  • WooCommerce: Import California Tax Rates (.csv)
    It took me ages to find a way to import ALL California tax rates into WooCommerce. I started by hand, and after a while I said to myself “California is crazy! I wouldn’t want to be an accountant there!”. As usual, I looked for existing free and premium plugins, but I decided to do it […]
  • WooCommerce: How to Export/Import Products
    Maybe you don’t know that, but WooCommerce has an inbuilt functionality for importing and exporting products from CSV/XML files. Therefore, most of the times, you don’t need a premium import/export plugin. Simply go to WordPress Dashboard > Products > All Products and click on Import (or Export) and follow the instructions. That’s it! This is […]
  • WooCommerce: Get Product IDs (All, by Tag, by Category)
    When you work with WooCommerce PHP snippets, you often need to “get” stuff off your WordPress database in order to make some calculations and return the result on the screen. And if there is something I often google is “How do I get all my store’s product IDs?“. Thankfully the wc_get_products WooCommerce function gives us […]
  • WooCommerce: Truncate Tag List @ Single Product Page
    If you use WooCommerce product tags, it’s possible that a product may belong to 10 or more of them. When that happens, the single product page displays a long list of tag links, which may take too much space (see the below screenshot to visualize this). Today’s snippet is indeed a way to truncate that […]
  • WooCommerce: Automatically Add Tag To Purchased Products
    This functionality can be helpful to those who need to differentiate purchased products from non-purchased ones. Think about a way to automatically discount non-tagged products, in order to entice more sales; or a function that only shows purchased products via a custom shortcode. No matter the application, “tagging” products upon purchase is super easy. Of […]

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 *