I'm not sure if WC Analytics can currently display this meta.
I checked the Advanced Order Export plugin and it looks like it can be set up to include these values.
The problem is that seat data is serialized, so it's hard to read.
What we can do is save the needed data as plain string meta keys during order creation. That way, the Advanced Order Export plugin can access them easily.
// Store seat id and discount info separately in order items
function checkout_order_processed_custom($order) {
if (!$order->get_meta('has_auditorium_product')) {
return;
}
foreach ($order->get_items() as $item) {
$seat_data = (array) $item->get_meta('seat_data');
if (empty($seat_data) || empty($seat_data['seatId'])) {
continue;
}
// Store seat ID in a separate meta field
$item->update_meta_data('_seat_id', $seat_data['seatId']);
// Process seat discount if available
$seat_discount = $item->get_meta('seat_discount');
if ($seat_discount) {
$seat_discount = (array) $seat_discount;
$item->update_meta_data('_seat_discount_name', $seat_discount['name'] ?? '');
$item->update_meta_data('_seat_discount_value', $seat_discount['value'] ?? 0);
$item->update_meta_data('_seat_discount_type', $seat_discount['type'] ?? 'fixed');
}
$item->save_meta_data();
}
}
add_action('woocommerce_checkout_order_created', '\Stachethemes\SeatPlanner\checkout_order_processed_custom', 10, 1);
add_action('woocommerce_store_api_checkout_order_processed', '\Stachethemes\SeatPlanner\checkout_order_processed_custom', 10, 1);
// Hide custom meta fields from the order item meta display in the admin area
add_filter('woocommerce_hidden_order_itemmeta', function($exclude_array) {
$exclude_array[] = '_seat_id';
$exclude_array[] = '_seat_discount_name';
$exclude_array[] = '_seat_discount_value';
$exclude_array[] = '_seat_discount_type';
return $exclude_array;
}, 10, 1);
This code creates meta keys with plain string values for the seat id and discount data.
With this code added your newly created orders will have these extra meta keys:
_seat_id
_seat_discount_name
_seat_discount_value
_seat_discount_type
So now you can go to the Export Orders page of the "Advanced Order Export" plugin and set it up.
Click on the "Setup fields to export" at the bottom to expand the settings:
On the right side select "Product order items"
Click on "Add field"
And add the _seat_id field like this:
Click "Confirm" and you should see the field here:
Drag it to the left column to include it in the export data.
Thank you for the code and thorough step by step instructions. I added the meta keys, however they were not available in the drop down selector as in your screenshot, and needed to be added manually.
I guess this will only work after a new order has been placed.
Is there a way to generate the new meta for already placed orders?
Great! I'm glad the solution worked. You can now remove the last code I sent.
Regarding the first code: keep in mind that if you update the plugin, you’ll lose the custom hooks since I suggested adding them directly to the plugin's main file for simplicity.
To make them update-safe, you can move the hooks to your child theme's functions.php file. Just remember that once you do this, the code won't be in the plugin's namespace anymore ( it will be in the global scope ), so you’ll need to remove the plugin namespace prefix from the add_action hooks like this:
Hi,
How can we export the orders including both the seat ID. and discount name?
I've tried with both via WC analytics and with the free "Advanced order export" plugin https://wordpress.org/plugins/woo-order-export-lite/ that let's you add custom filters.
All the best,
/John
Hi,
I'm not sure if WC Analytics can currently display this meta.
I checked the Advanced Order Export plugin and it looks like it can be set up to include these values.
The problem is that seat data is serialized, so it's hard to read.
What we can do is save the needed data as plain string meta keys during order creation. That way, the Advanced Order Export plugin can access them easily.
Instructions:
Open the Seat Planner main file found in
wp-content/plugins/stachethemes-seat-planner/stachethemes-seat-planner.php
At the bottom of the file insert this code:
This code creates meta keys with plain string values for the seat id and discount data.
With this code added your newly created orders will have these extra meta keys:
So now you can go to the Export Orders page of the "Advanced Order Export" plugin and set it up.
Click on the "Setup fields to export" at the bottom to expand the settings:
On the right side select "Product order items"
Click on "Add field"
And add the _seat_id field like this:
Click "Confirm" and you should see the field here:
Drag it to the left column to include it in the export data.
You can do the same for the discount fields.
Stachethemes Developer
Thank you for the code and thorough step by step instructions. I added the meta keys, however they were not available in the drop down selector as in your screenshot, and needed to be added manually.
I guess this will only work after a new order has been placed.
Is there a way to generate the new meta for already placed orders?
Best,
/John
Attached files: _seat_id.jpg
Yes, this will work for your next orders only.
You can run a php code that will modify the existing orders as well:
Below the other code I sent you place this one:
And then you can run this function from the front-end by adding ?seat_order_update_meta=1 to the website url.
E.g. https://my-website.com/?seat_order_update_meta=1
If executed you should see a blank page with "Done" text.
Remove this code once the function is executed.
Stachethemes Developer
Thanks again for your responsiveness Zhivko.
This worked great.
Best,
/John
Great! I'm glad the solution worked. You can now remove the last code I sent.
Regarding the first code: keep in mind that if you update the plugin, you’ll lose the custom hooks since I suggested adding them directly to the plugin's main file for simplicity.
To make them update-safe, you can move the hooks to your child theme's functions.php file. Just remember that once you do this, the code won't be in the plugin's namespace anymore ( it will be in the global scope ), so you’ll need to remove the plugin namespace prefix from the add_action hooks like this:
Even better if you use some Code Snippets plugin you can insert the code as a PHP Snippet.
Stachethemes Developer
Updated and safe. Thanks again for this solution.
/John