Modify Existing Fields
Need to change how fields appear? Add prefixes. Swap name order. Convert currency.
Here’s how.
Add order number prefix
Want “KTR-1001” instead of “1001”? Simple.
|
1 2 3 4 5 |
// add order prefix add_filter('woe_get_order_value_order_number', function ($value, $order, $fieldname) { return "KTR-" . $value; }, 10, 3); |
Change “KTR-” to whatever you need. “PO-” for purchase orders. “INV-” for invoices.
Remove line breaks from customer notes
Customer notes often have messy line breaks. Your CSV ends up broken.
|
1 2 3 4 5 |
// remove line breaks from customer note add_filter('woe_get_order_value_customer_note',function ($value, $order,$fieldname) { return preg_replace( "/r|n/", "", $value); },10,3); |
Clean text. One line. No formatting issues.
Swap first and last names
Some systems want “Last, First” instead of “First Last”.
|
1 2 3 4 5 |
// swap last and first names in "Shipping Full Name" add_filter('woe_get_order_value_shipping_full_name',function ($value, $order,$fieldname) { return $order->get_shipping_last_name(). ' ' . $order->get_shipping_first_name(); },10,3); |
Same for billing names. Change shipping_full_name to billing_full_name.
Rename shipping methods
“Flat rate” becomes “STANDARD”. “Free shipping” becomes “PROMO”.
|
1 2 3 4 5 6 7 |
// remap shipping method titles add_filter('woe_get_order_value_shipping_method_title', function ($value, $order, $fieldname) { if($value == 'Flat rate') // copy these 2 lines for other mappings $value = 'STANDARD'; return $value; }, 10, 3); |
Add as many mappings as needed. Your accounting system will thank you.
Format product weight to 3 decimals
0.2 becomes 0.200. 0.12 becomes 0.120.
|
1 2 3 4 5 |
// format product weight, 0.2->0.200 and 0.12->0.120 add_filter('woe_get_order_product_value_weight', function ($value, $order, $item, $product,$Item_meta) { return number_format($value,3,'.',''); }, 10, 5); |
Perfect for shipping integrations that expect consistent decimal places.
Fix apostrophes in “WC Fields Factory”
This plugin sometimes breaks apostrophes. Fix with this:
|
1 2 3 4 5 6 7 8 9 |
// fix problem with apostrophe in "WC Fields Factory" add_filter( "woe_get_order_product_item_meta", function($item_meta ){ foreach($item_meta as $k=>$v) { $k2 = html_entity_decode ($k,ENT_QUOTES); $item_meta[$k2] = $v; } return $item_meta; }); |
No more “Don’t” showing up. Just “Don’t”.
Count only paid orders for customer total
By default, “Customer Total Orders” counts everything. Even cancelled ones.
This fixes that. Counts only processing and completed orders.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// modify field "Customer Total Orders" to count only paid orders add_filter("woocommerce_customer_get_order_count", function($value,$customer){ global $wpdb; $statuses = array("wc-processing","wc-completed"); return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts as posts LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id WHERE meta.meta_key = '_customer_user' AND posts.post_type = 'shop_order' AND posts.post_status IN ( '" . implode( "','", $statuses) . "' ) AND meta_value = '" . esc_sql( $customer->get_id() ) . "'" ); },10,2); |
Pro tip: Add "wc-on-hold" to the array if you want pending payments included.
Convert currency from CNY to USD
Run a Chinese store? Sell in Yuan but report in Dollars?
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
//convert "order total" and "item price" from CNY to USD class WOE_currency_mod { var $rate = false; function __construct() { add_filter('woe_get_order_value_order_total',array($this,'convert_cny_usd'), 10, 3); add_filter('woe_get_order_product_value_item_price',array($this,'convert_cny_usd'), 10, 3); } function convert_cny_usd($value, $order,$fieldname) { return round( $value * $this->get_rate(), 2 ); } function get_rate() { if( $this->rate === false) { $response = wp_remote_get("http://ratesapi.io/api/latest?base=CNY&symbols=USD"); $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); $this->rate = $api_response['rates']['USD']; } return $this->rate; } } new WOE_currency_mod(); |
What it does: Fetches live exchange rate. Converts order total and item prices. Rounds to 2 decimals.
Warning: This uses an external API. If the API fails, the rate defaults to false. Test before running large exports.
Pro tip: Change base=CNY to your currency code. Change symbols=USD to your target currency.
Where to put these snippets
Go to Misc Settings in your export profile. Paste code at the bottom.
Each snippet modifies one specific field. Use multiple snippets together. They won’t conflict.
Advanced Order Export for WooCommerce handles the export. These snippets change field values before they reach your file.
Common mistake
Using the wrong field name in the filter.
woe_get_order_value_shipping_method_title is different from woe_get_order_value_shipping_method.
Check your field list. Use the exact name from Setup Fields.
Pro tip
Combine multiple modifications. Add prefix. Swap names. Convert currency. All in one export.
Test each change separately. Once verified, combine them. One filter per field is fine.