Last active
August 30, 2017 22:07
-
-
Save Garconis/3731392f83e84063b59c3cd457ad5eb7 to your computer and use it in GitHub Desktop.
WooCommerce Customer / Order CSV Export | Add a column to show custom text based on if there was sales tax or not
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 sees if your order or line item had any tax, and if so, it fills your custom column with "Taxed". Otherwise, the column will say "Not Taxed". | |
*/ | |
function fs_wc_csv_export_trim_data( $order_data ) { | |
for( $i = 0; $i < count( $order_data ); $i++ ) { | |
if ( isset( $order_data[ $i ]['order_line/tax_id/id'] ) ) { | |
$taxage = $order_data[ $i ]['tax_total']; | |
//If there is tax, then change the amount to custom text instead | |
if( $taxage > 0 ) { | |
$order_data[ $i ]['order_line/tax_id/id'] = 'Taxed'; | |
} | |
else { | |
$order_data[ $i ]['order_line/tax_id/id'] = 'Not Taxed'; | |
} | |
} | |
} | |
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