Skip to content
Advertisement

WooCommerce Order Export: Get custom data per line item

I’m using the “WooCommerce Customer / Order / Coupon Export” plugin to export my orders as a CSV file.

I’m exporting the orders in a one row per item format. This means that every order has multiple lines. One line per order item.

Now I want to add some extra data to every line item. For example the author (in our case vendor) of the item. I found a good way to add exta data to the export. It could be found in the documentation of the plugin: https://docs.woocommerce.com/document/ordercustomer-csv-export-developer-documentation/#section-14

It works but it’s not exactly what I need. I could add some data to the whole order. So every line item gets the same data.

So I tried to change the code and go through every line item. Unfortunatly with the same result. Every line item gets the same data. In my case the data from the last item of the order.

Here’s how I’ve changed the step 2 of the example from the official docs:

JavaScript

I guess that I’m adding the data at the wrong position?! But I couldn’t figure out where the problem is.

EDIT: After the comment from @CBroe I tried to use wc_customer_order_csv_export_order_line_item.

I found an example here but that’s destroying my CSV file:

JavaScript

But I’m still trying…

Advertisement

Answer

I found an answer. It was an example hidden in the official docs: https://github.com/skyverge/wc-plugins-snippets/blob/master/woocommerce-customer-order-coupon-export/csv/add-item-meta-to-order-export.php

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement