How to add fields in the WooCommerce product export section

WooCommerce allows exporting products from the WordPress admin, but by default, it does not offer the ability to add custom filters. In this article, I will show you how to add custom fields in the product export section and use them as filters to refine the export.

As an example, we will add a multi-select field to filter by product tags (product_tags).

 

Adding a multi-select field in the export section

To add a custom field in the export section, we need to use the woocommerce_product_export_rowhook, which allows us to insert HTML elements within the export form.

 'product_tag',
        'hide_empty' => false
    ) );
    
    if ( empty( $tags ) || is_wp_error( $tags ) ) {
        return;
    }
    
    echo '';
    echo '';
    echo '';
    echo '';
    echo '';
    echo '';
} );

This will add a multi-select field where users can choose product tags before exporting them.

 

Applying a filter based on the added field

Once the field is added, we need to use the woocommerce_product_export_product_query_argshook to modify the export query and filter the products based on the user’s selection.

 'product_tag',
                'field'    => 'slug',
                'terms'    => (array) $form_data['product_tags']
            );
        }
    }
    return $args;
} );

This ensures that only the products with the selected tags are exported.

 

With these code snippets, you can add custom fields in the WooCommerce export section and use them to filter products before exporting them. In this example, we added a filter based on product tags, but you can apply the same methodology to other custom fields as needed.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Back to Top
0
Would love your thoughts, please comment.x
()
x