WooCommerce – Adding Product Attributes to CSV Export

With the help of a more knowledgeable colleague, we got it working. Here’s the code:

/** Add custom column headers **/
function wc_csv_export_modify_column_headers( $column_headers ) {

    $new_headers = array(
        'fund' => 'fund',
        'appeal' => 'appeal_code',
    );

    return array_merge( $column_headers, $new_headers );
}
add_filter( 'wc_customer_order_csv_export_order_headers', 
            'wc_csv_export_modify_column_headers' );

/** Set the data for each for custom columns **/
function wc_csv_export_modify_row_data( $order_data, $item, $order, $csv_generator ) {

    // Determine the product ID from the SKU, and use that to find the fund and appeal code
    $pid = wc_get_product_id_by_sku($item[sku]);
    $fund = wc_get_product_terms( $pid, 'pa_fund' );
    $appeal = wc_get_product_terms( $pid, 'pa_appeal-code' );

    // Add the fund & appeal code to the order_data & return each line
    $order_data["fund"] = $fund[0];
    $order_data["appeal"] = $appeal[0];
    return $order_data;
}
add_filter( 'wc_customer_order_csv_export_order_row_one_row_per_item',
            'wc_csv_export_modify_row_data', 10, 4 );

tech