WooCommerce – Export CSV with custom meta fields

Taken from the WooCommerce documentation: http://wcdocs.woothemes.com/user-guide/extensions/ordercustomer-csv-exporter/#section-4

This post is in relation to the ‘Order/Customer CSV Exporter‘ plugin.

Adding custom meta fields to exports

Starting from version 1.6 there has been possibility to add custom meta fields to the orders export csv output. Adding custom meta fields to the export can be done using ’woocommerce_export_csv_extra_columns’ filter. Below you can find a simple example how to add custom meta fields using a custom sites plugin.

First you need to add a filter named ‘woocommerce_export_csv_extra_columns’. In this filter you will define also the function that will be used to actually add the custom meta. In this example the function is called ‘sites_add_custom_meta’.

Next you define the function sites_add_custom_meta. In this function you have two things you need to define. First in the columns array you need to define the titles of your custom meta fields and then in the data array you need to define actual meta field name where the data for that field is located at. You need to have the same order in both arrays to be able to have correct information output under right column title.

add_filter( 'woocommerce_export_csv_extra_columns', 'sites_add_custom_meta', 10);
function sites_add_custom_meta() {
  //$custom_meta_fields['columns'][] = 'Ticket holders Name';
  $custom_meta_fields['data'][] = 'Ticket holders Name';
  return $custom_meta_fields;

After you have done this you should start seeing your custom meta field appearing in the orders export csv.


Tags: , , ,

No comments yet.

Leave a Reply