Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Garconis/812bcc7925bf3f54c76202855156cbbe to your computer and use it in GitHub Desktop.
Save Garconis/812bcc7925bf3f54c76202855156cbbe to your computer and use it in GitHub Desktop.
WooCommerce Customer / Order CSV Export | Add a custom meta field from the User (Customer) associated with a WooCommerce Order
<?php
/**
* Order Export
* Within the Custom Formats > Column Mapping, add your custom column name and set the Data Source to Static, and leave the Value field blank (since we set it here instead anyway)
* This function takes that custom field (based on the name you set it to) and then finds the user associated with the order (based on the customer_id of the order), and then displays the user's custom field you specify.
*/
// Tweak content of certain fields in the order export
function fs_wc_csv_export_trim_data( $order_data ) {
for( $i = 0; $i < count( $order_data ); $i++ ) {
// Get custom field from the user
if ( isset( $order_data[ $i ]['odoo_customer_id'] ) ) { $order_data[ $i ]['odoo_customer_id'] = mb_strimwidth(get_user_meta( $order_data[ $i ]['customer_id'], 'your_user_custom_field', true), 0, 30, ""); }
}
return $order_data;
}
add_filter( 'wc_customer_order_csv_export_order_row', 'fs_wc_csv_export_trim_data' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment