Order Tags
Using the Order Tags plugin? Need to filter exports by specific tags? Export the tags themselves? Let me tell how via Advanced Order Export for WooCommerce.
What this code does
Two things:
- Adds an “Order Tags” column to your export
- Adds a filter at the top of the export form. Filter orders by which tags they have.
The complete code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
// Filter by order tags + export field "Order tags" class Woe_Order_Tags { function __construct() { //add settings add_action("woe_settings_form_view_top", array($this,"draw_options") ); // start filtering add_filter("woe_settings_validate_defaults", function($settings) { $settings[ 'order_tags' ] = array_filter($settings[ 'order_tags' ]); if( !empty($settings[ 'order_tags' ]) ) $this->set_filter($settings[ 'order_tags' ]); return $settings; }); //add field to export add_filter('woe_get_order_fields', function ($fields) { $fields['wcot_order_tags'] = array( 'label' => 'Order Tags', 'colname' => 'Order Tags', 'checked' => 1 ); return $fields; }); //set field value add_filter('woe_get_order_value_wcot_order_tags', function ($value,$order, $field) { $order_tags = wcot_order_tags_get_order_tags( $order->get_id() ); $value= join(",", wp_list_pluck($order_tags,"name")); return $value; }, 10, 3); } function draw_options($settings){ if( empty($settings[ 'order_tags' ]) ) $settings[ 'order_tags' ] = array(); echo "<strong>Order tags:</strong>"; $terms = get_terms([ 'taxonomy' => 'wcot_order_tag', 'hide_empty' => false, ]); echo "<input name="settings[order_tags][]" type="hidden" value="0" />"; foreach($terms as $term) { $checked = in_array($term->term_id,$settings[ 'order_tags' ]) ? 'checked': ''; echo "<input checked="checked" name="settings[order_tags][]" type="checkbox" value="{$term->term_id}" /> {$term->name} "; } echo " |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<br /><code>"; } function set_filter($tags){ global $wpdb; $terms = join(",", $tags); $sql = "SELECT object_id FROM {$wpdb->prefix}term_relationships AS TR INNER JOIN {$wpdb->prefix}term_taxonomy AS TT ON TR.term_taxonomy_id = TT.term_taxonomy_id INNER JOIN {$wpdb->prefix}terms AS T ON TT.term_id = T.term_id WHERE TT.taxonomy = 'wcot_order_tag' AND T.term_id IN($terms)"; $orders = $wpdb->get_col($sql); add_action( 'woe_sql_get_order_ids_where', function ($where, $settings) use ($orders) { if(!$orders) $orders[] = "0"; // we don't have any matched orders, so export must be EMPTY! $orders = join(",", $orders); $where[] = "orders.ID IN ($orders)"; return $where; }, 10, 2); } } new Woe_Order_Tags(); |
Step 1: Install the code
Copy the entire block. Paste into your theme’s functions.php.
Step 2: What appears
Open Advanced Order Export for WooCommerce. Create or edit an export profile.
At the top of the form, you’ll see:
Order tags: [ ] VIP [ ] Wholesale [ ] International [ ] Rush
Check any combination. Only orders with those tags will export.
In Setup Fields → Others, you’ll find “Order Tags” as a new column.
Step 3: Filter by tags
Check one or more tags. The export only includes orders that have ALL checked tags.
Example: Check “VIP” and “Rush”. Only orders with BOTH tags export.
Step 4: Export the tags
Add “Order Tags” to your exported columns. Each order shows its tags. Comma-separated.
Sample output:
| Order # | Customer | Order Tags |
|---|---|---|
| 1001 | John Smith | VIP, Wholesale |
| 1002 | Jane Doe | Rush |
| 1003 | Bob Brown | International, Wholesale |
When you need this
You tag orders by customer type (VIP, Wholesale, Retail). Need to export only wholesale orders.
You tag orders by urgency (Rush, Standard). Want to process rush orders separately.
You tag orders by region (Domestic, International). Need regional reports.
Common mistake
The code expects the Order Tags plugin to be active. Taxonomy wcot_order_tag must exist.
No tags created yet? Go create some tags in WordPress admin. Assign them to orders. Then test the export.
Empty export?
Checked tags but got zero orders? Two possibilities:
- No orders have those tags
- You checked multiple tags, but no order has ALL of them
Try checking just one tag first. Verify it works.
Pro tip
Want orders with ANY checked tag (not ALL)? Change the SQL logic. Contact plugin support for that modification.
Need to see tag IDs? Look in the URL when editing a tag. Or query the database.
Real talk
Order Tags plugin stores tags as a custom taxonomy. Not regular post meta. That’s why normal exports miss them.
This code bridges that gap. Your tags become filterable and exportable.
Perfect for stores that categorize orders beyond standard statuses. Your team can finally export by “VIP” or “Wholesale” with one click.
