1. Home
  2. Knowledge Base
  3. WooCommerce Product Add-Ons Ultimate
  4. Get add-ons meta data from the order
  1. Home
  2. Knowledge Base
  3. Orders
  4. Get add-ons meta data from the order
  1. Home
  2. Knowledge Base
  3. Advanced
  4. Get add-ons meta data from the order

Get add-ons meta data from the order

If you need to get add-ons data from the order, you can use this function:

<?php
/**
* Get add-ons meta data from the order
*/
function prefix_order_data( $order_id ) {
$order = wc_get_order( $order_id );
$order_line_items = $order->get_items();
foreach( $order_line_items as $line_item ) {
// This is your add-ons data for each line item
$addons_data = $line_item->get_meta( 'product_extras' );
}
}

Product add-ons are stored as meta data in the order for each line item.

Here’s a typical return value:

Array
(
[product_id] => 2751
[title] => Uploads
[groups] => Array
(
[2752] => Array
(
[2753] => Array
(
[type] => checkbox
[label] => Checkbox
[id] => pewc_group_2752_2753
[group_id] => 2752
[field_id] => 2753
[price] => 0
[value] => __checked__
[flat_rate] => Array
(
)
)
[2756] => Array
(
[type] => checkbox
[label] => Default
[id] => pewc_group_2752_2756
[group_id] => 2752
[field_id] => 2756
[price] => 2
[value] => __checked__
[flat_rate] => Array
(
)
)
[2754] => Array
(
[files] => Array
(
[0] => Array
(
[file] => /Applications/MAMP/htdocs/catapult_themes/wp-content/uploads/sites/19/product-extras/2019/07/c4ca4238a0b923820dcc509a6f75849b/calc-field-14.jpeg
[name] => calc-field.jpeg
[display] => calc-field.jpeg
[type] => image/jpeg
[tmp_name] => /Applications/MAMP/tmp/php/phpfTpVKC
[error] => 0
[size] => 145851
[url] => http://localhost/catapult_themes/product-extras/wp-content/uploads/sites/19/product-extras/2019/07/c4ca4238a0b923820dcc509a6f75849b/calc-field-14.jpeg
)
)
[type] => upload
[label] => Upload
[id] => pewc_group_2752_2754
[group_id] => 2752
[field_id] => 2754
[price] => 5
[flat_rate] => Array
(
)
)
)
)
[price_with_extras] => 12
)

You can see that the data is returned as an array. The groups element contains an array of each field by group ID.

Was this article helpful?

Need More Support?

If you can't find the answer that you're looking for, then please use the link below to raise a support ticket.
Contact Support

Related Articles