I’m looking to create Trello cards from my WooCommerce orders which I can do with some basic features (or one item in an order) with no problem.
However, when orders contain multiple line items, these need to be iterated through to be output to the same Trello card. Each order also contains a few pieces of meta_data that I also want to display in the Trello card.
I think I need to loop through the orders line_items, then within that loop, loop through each line_items meta_data however I can’t seem to receive all of the data or all of the fields into 1 card.
Is anyone able to point me in the right direction?
An example of some JSON received from WooCom with 2 x line items and multiple meta fields for each item is below:
{
"id": 1154,
"parent_id": 0,
"status": "processing",
"currency": "GBP",
"version": "8.9.1",
"prices_include_tax": true,
"date_created": "2024-05-31T11:08:06",
"date_modified": "2024-05-31T11:10:07",
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "12.50",
"shipping_tax": "2.50",
"cart_tax": "21.00",
"total": "141.00",
"total_tax": "23.50",
"customer_id": 0,
"order_key": "wc_order_iODE9zHx1HFck",
"billing": {
"first_name": "Simon",
"last_name": "Testing",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": "GB",
"email": "",
"phone": ""
},
"shipping": {
"first_name": "Simon",
"last_name": "Testing",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": "GB",
"phone": ""
},
"payment_method": "stripe",
"payment_method_title": "Credit / Debit Card",
"transaction_id": "ch_3PMTJcGQr51XgAis0Zv3KtNr",
"customer_ip_address": "X.X.X.X",
"customer_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
"created_via": "checkout",
"customer_note": "",
"date_completed": null,
"date_paid": "2024-05-31T11:08:09",
"cart_hash": "cb01843e2250c0903d2cd14620419a03",
"number": "1154",
"meta_data": [
{
"id": 921,
"key": "_stripe_charge_captured",
"value": "yes"
},
{
"id": 924,
"key": "_stripe_currency",
"value": "GBP"
},
{
"id": 918,
"key": "_stripe_customer_id",
"value": "cus_QCt5m2f5W31uFG"
},
{
"id": 922,
"key": "_stripe_fee",
"value": "4.78"
},
{
"id": 920,
"key": "_stripe_intent_id",
"value": "pi_3PMTJcGQr51XgAis0qLYgrh0"
},
{
"id": 923,
"key": "_stripe_net",
"value": "136.22"
},
{
"id": 917,
"key": "_stripe_source_id",
"value": "pm_1PMTJZGQr51XgAisv7gYQaZy"
},
{
"id": 919,
"key": "_stripe_upe_payment_type",
"value": "card"
},
{
"id": 916,
"key": "_wc_order_attribution_device_type",
"value": "Desktop"
},
{
"id": 914,
"key": "_wc_order_attribution_session_count",
"value": "3"
},
{
"id": 911,
"key": "_wc_order_attribution_session_entry",
"value": "https://domain.tld"
},
{
"id": 913,
"key": "_wc_order_attribution_session_pages",
"value": "5"
},
{
"id": 912,
"key": "_wc_order_attribution_session_start_time",
"value": "2024-05-31 08:11:40"
},
{
"id": 909,
"key": "_wc_order_attribution_source_type",
"value": "typein"
},
{
"id": 915,
"key": "_wc_order_attribution_user_agent",
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
},
{
"id": 910,
"key": "_wc_order_attribution_utm_source",
"value": "(direct)"
},
{
"id": 905,
"key": "is_vat_exempt",
"value": "no"
},
{
"id": 908,
"key": "szbd_shipping_origin",
"value": "Main Location"
}
],
"line_items": [
{
"id": 845,
"name": "Occasion Flowers - £96",
"product_id": 279,
"variation_id": 285,
"quantity": 1,
"tax_class": "",
"subtotal": "80.00",
"subtotal_tax": "16.00",
"total": "80.00",
"total_tax": "16.00",
"taxes": [
{
"id": 1,
"total": "16",
"subtotal": "16"
}
],
"meta_data": [
{
"id": 6582,
"key": "bouquet-value",
"value": "£96",
"display_key": "Bouquet Value",
"display_value": "£96"
},
{
"id": 6583,
"key": "_WCPA_order_meta_data",
"value": {
"sec_866324c206ae14": {
"extra": {
"section_id": "sec_866324c206ae14",
"clStatus": "visible",
"key": "sec_866324c206ae14",
"name": "Default",
"price": 0,
"weight": 0,
"form_id": 804,
"isClone": false,
"parentKey": false,
"form_rules": {
"exclude_from_discount": false,
"fee_label": "Fee",
"disp_hide_options_price": false,
"disp_show_section_price": false,
"disp_show_field_price": true,
"layout_option": "standard",
"pric_use_as_fee": false,
"process_fee_as": "woo_fee"
}
},
"fields": [
[
{
"type": "date",
"name": "date_7233161117",
"label": "Date",
"elementId": "date_7233161117",
"value": "2024-06-20",
"quantity": false,
"clStatus": "visible",
"price": false,
"weight": false,
"form_data": {
"name": "date_7233161117",
"label": "Date",
"enablePrice": false,
"price": "",
"active": true,
"required": true,
"elementId": "date_7233161117"
},
"map_to_checkout": false,
"dateFormat": "d/m/Y",
"meta_id": 6607
}
]
]
},
"sec_4661d1fec32d44": {
"extra": {
"section_id": "sec_4661d1fec32d44",
"clStatus": "visible",
"key": "sec_4661d1fec32d44",
"name": "Default",
"price": 0,
"weight": 0,
"form_id": 290,
"isClone": false,
"parentKey": false,
"form_rules": {
"exclude_from_discount": false,
"fee_label": "Fee",
"disp_hide_options_price": false,
"disp_show_section_price": false,
"disp_show_field_price": true,
"layout_option": "standard",
"pric_use_as_fee": false,
"process_fee_as": "woo_fee"
}
},
"fields": [
[
{
"type": "textarea",
"name": "textarea_1847657581",
"label": "Other bouquet/arrangement notes",
"elementId": "textarea_1847657581",
"value": "Only roses, please",
"quantity": false,
"clStatus": "visible",
"price": false,
"weight": false,
"form_data": {
"name": "textarea_1847657581",
"label": "Other bouquet/arrangement notes",
"value": "",
"enablePrice": false,
"price": "",
"active": true,
"required": false,
"elementId": "textarea_1847657581"
},
"map_to_checkout": false,
"meta_id": 6608
}
],
[
{
"type": "select",
"name": "select_9007891108",
"label": "Include a message?",
"elementId": "select_9007891108",
"value": [
{
"i": 0,
"value": "yes",
"label": "Yes, please",
"price": 0,
"weight": 0
}
],
"quantity": false,
"clStatus": "visible",
"price": false,
"weight": false,
"form_data": {
"name": "select_9007891108",
"label": "Include a message?",
"enablePrice": false,
"price": "",
"active": true,
"required": true,
"elementId": "select_9007891108"
},
"map_to_checkout": false,
"meta_id": 6609
},
{
"type": "textarea",
"name": "textarea_9882711805",
"label": "Message",
"elementId": "textarea_9882711805",
"value": "Some words for the note.",
"quantity": false,
"clStatus": "visible",
"price": false,
"weight": false,
"form_data": {
"name": "textarea_9882711805",
"label": "Message",
"value": "",
"enablePrice": false,
"price": "",
"active": true,
"required": true,
"elementId": "textarea_9882711805"
},
"map_to_checkout": false,
"meta_id": 6610
}
]
]
}
},
"display_key": "_WCPA_order_meta_data",
"display_value": {
"sec_866324c206ae14": {
"extra": {
"section_id": "sec_866324c206ae14",
"clStatus": "visible",
"key": "sec_866324c206ae14",
"name": "Default",
"price": 0,
"weight": 0,
"form_id": 804,
"isClone": false,
"parentKey": false,
"form_rules": {
"exclude_from_discount": false,
"fee_label": "Fee",
"disp_hide_options_price": false,
"disp_show_section_price": false,
"disp_show_field_price": true,
"layout_option": "standard",
"pric_use_as_fee": false,
"process_fee_as": "woo_fee"
}
},
"fields": [
[
{
"type": "date",
"name": "date_7233161117",
"label": "Date",
"elementId": "date_7233161117",
"value": "2024-06-20",
"quantity": false,
"clStatus": "visible",
"price": false,
"weight": false,
"form_data": {
"name": "date_7233161117",
"label": "Date",
"enablePrice": false,
"price": "",
"active": true,
"required": true,
"elementId": "date_7233161117"
},
"map_to_checkout": false,
"dateFormat": "d/m/Y",
"meta_id": 6607
}
]
]
},
"sec_4661d1fec32d44": {
"extra": {
"section_id": "sec_4661d1fec32d44",
"clStatus": "visible",
"key": "sec_4661d1fec32d44",
"name": "Default",
"price": 0,
"weight": 0,
"form_id": 290,
"isClone": false,
"parentKey": false,
"form_rules": {
"exclude_from_discount": false,
"fee_label": "Fee",
"disp_hide_options_price": false,
"disp_show_section_price": false,
"disp_show_field_price": true,
"layout_option": "standard",
"pric_use_as_fee": false,
"process_fee_as": "woo_fee"
}
},
"fields": [
[
{
"type": "textarea",
"name": "textarea_1847657581",
"label": "Other bouquet/arrangement notes",
"elementId": "textarea_1847657581",
"value": "Only roses, please",
"quantity": false,
"clStatus": "visible",
"price": false,
"weight": false,
"form_data": {
"name": "textarea_1847657581",
"label": "Other bouquet/arrangement notes",
"value": "",
"enablePrice": false,
"price": "",
"active": true,
"required": false,
"elementId": "textarea_1847657581"
},
"map_to_checkout": false,
"meta_id": 6608
}
],
[
{
"type": "select",
"name": "select_9007891108",
"label": "Include a message?",
"elementId": "select_9007891108",
"value": [
{
"i": 0,
"value": "yes",
"label": "Yes, please",
"price": 0,
"weight": 0
}
],
"quantity": false,
"clStatus": "visible",
"price": false,
"weight": false,
"form_data": {
"name": "select_9007891108",
"label": "Include a message?",
"enablePrice": false,
"price": "",
"active": true,
"required": true,
"elementId": "select_9007891108"
},
"map_to_checkout": false,
"meta_id": 6609
},
{
"type": "textarea",
"name": "textarea_9882711805",
"label": "Message",
"elementId": "textarea_9882711805",
"value": "Some words for the note.",
"quantity": false,
"clStatus": "visible",
"price": false,
"weight": false,
"form_data": {
"name": "textarea_9882711805",
"label": "Message",
"value": "",
"enablePrice": false,
"price": "",
"active": true,
"required": true,
"elementId": "textarea_9882711805"
},
"map_to_checkout": false,
"meta_id": 6610
}
]
]
}
}
},
{
"id": 6607,
"key": "Date",
"value": "2024-06-20",
"display_key": "Date",
"display_value": "20/06/2024"
},
{
"id": 6608,
"key": "Other bouquet/arrangement notes",
"value": "Only roses, please",
"display_key": "Other bouquet/arrangement notes",
"display_value": "Only roses, please"
},
{
"id": 6609,
"key": "Include a message?",
"value": "Yes, please | yes",
"display_key": "Include a message?",
"display_value": "Yes, please"
},
{
"id": 6610,
"key": "Message",
"value": "Some words for the note.",
"display_key": "Message",
"display_value": "Some words for the note."
},
{
"id": 6611,
"key": "_wcpa_order_meta_key_label_map",
"value": {
"6607": "Date",
"6608": "Other bouquet/arrangement notes",
"6609": "Include a message?",
"6610": "Message"
},
"display_key": "_wcpa_order_meta_key_label_map",
"display_value": {
"6607": "Date",
"6608": "Other bouquet/arrangement notes",
"6609": "Include a message?",
"6610": "Message"
}
}
],
"sku": "",
"price": 80,
"image": {
"id": 107,
"src": "https://domain.tldwp-content/uploads/2024/04/bouquet-summer-scaled-1.jpeg"
},
"parent_name": "Occasion Flowers"
},
{
"id": 846,
"name": "Serene - White Tulips",
"product_id": 208,
"variation_id": 209,
"quantity": 1,
"tax_class": "",
"subtotal": "25.00",
"subtotal_tax": "5.00",
"total": "25.00",
"total_tax": "5.00",
"taxes": [
{
"id": 1,
"total": "5",
"subtotal": "5"
}
],
"meta_data": [
{
"id": 6593,
"key": "tulip-colour",
"value": "White Tulips",
"display_key": "Tulip Colour",
"display_value": "White Tulips"
},
{
"id": 6594,
"key": "_WCPA_order_meta_data",
"value": {
"sec_866324c206ae14": {
"extra": {
"section_id": "sec_866324c206ae14",
"clStatus": "visible",
"key": "sec_866324c206ae14",
"name": "Default",
"price": 0,
"weight": 0,
"form_id": 804,
"isClone": false,
"parentKey": false,
"form_rules": {
"exclude_from_discount": false,
"fee_label": "Fee",
"disp_hide_options_price": false,
"disp_show_section_price": false,
"disp_show_field_price": true,
"layout_option": "standard",
"pric_use_as_fee": false,
"process_fee_as": "woo_fee"
}
},
"fields": [
[
{
"type": "date",
"name": "date_7233161117",
"label": "Date",
"elementId": "date_7233161117",
"value": "2024-06-12",
"quantity": false,
"clStatus": "visible",
"price": false,
"weight": false,
"form_data": {
"name": "date_7233161117",
"label": "Date",
"enablePrice": false,
"price": "",
"active": true,
"required": true,
"elementId": "date_7233161117"
},
"map_to_checkout": false,
"dateFormat": "d/m/Y",
"meta_id": 6612
}
]
]
},
"sec_86621060a3ad83": {
"extra": {
"section_id": "sec_86621060a3ad83",
"clStatus": "visible",
"key": "sec_86621060a3ad83",
"name": "Default",
"price": 0,
"weight": 0,
"form_id": 462,
"isClone": false,
"parentKey": false,
"form_rules": {
"exclude_from_discount": false,
"fee_label": "Fee",
"disp_hide_options_price": false,
"disp_show_section_price": false,
"disp_show_field_price": true,
"layout_option": "standard",
"pric_use_as_fee": false,
"process_fee_as": "woo_fee"
}
},
"fields": [
[
{
"type": "select",
"name": "select_86621060a3adce",
"label": "Include a message?",
"elementId": "select_86621060a3adce",
"value": [
{
"i": 0,
"value": "yes",
"label": "Yes, please",
"price": 0,
"weight": 0
}
],
"quantity": false,
"clStatus": "visible",
"price": false,
"weight": false,
"form_data": {
"name": "select_86621060a3adce",
"label": "Include a message?",
"enablePrice": false,
"price": "",
"active": true,
"required": true,
"elementId": "select_86621060a3adce"
},
"map_to_checkout": false,
"meta_id": 6613
},
{
"type": "textarea",
"name": "textarea_96621060a3adde",
"label": "Message",
"elementId": "textarea_96621060a3adde",
"value": "A lovely message.",
"quantity": false,
"clStatus": "visible",
"price": false,
"weight": false,
"form_data": {
"name": "textarea_96621060a3adde",
"label": "Message",
"value": "",
"enablePrice": false,
"price": "",
"active": true,
"required": true,
"elementId": "textarea_96621060a3adde"
},
"map_to_checkout": false,
"meta_id": 6614
}
]
]
}
},
"display_key": "_WCPA_order_meta_data",
"display_value": {
"sec_866324c206ae14": {
"extra": {
"section_id": "sec_866324c206ae14",
"clStatus": "visible",
"key": "sec_866324c206ae14",
"name": "Default",
"price": 0,
"weight": 0,
"form_id": 804,
"isClone": false,
"parentKey": false,
"form_rules": {
"exclude_from_discount": false,
"fee_label": "Fee",
"disp_hide_options_price": false,
"disp_show_section_price": false,
"disp_show_field_price": true,
"layout_option": "standard",
"pric_use_as_fee": false,
"process_fee_as": "woo_fee"
}
},
"fields": [
[
{
"type": "date",
"name": "date_7233161117",
"label": "Date",
"elementId": "date_7233161117",
"value": "2024-06-12",
"quantity": false,
"clStatus": "visible",
"price": false,
"weight": false,
"form_data": {
"name": "date_7233161117",
"label": "Date",
"enablePrice": false,
"price": "",
"active": true,
"required": true,
"elementId": "date_7233161117"
},
"map_to_checkout": false,
"dateFormat": "d/m/Y",
"meta_id": 6612
}
]
]
},
"sec_86621060a3ad83": {
"extra": {
"section_id": "sec_86621060a3ad83",
"clStatus": "visible",
"key": "sec_86621060a3ad83",
"name": "Default",
"price": 0,
"weight": 0,
"form_id": 462,
"isClone": false,
"parentKey": false,
"form_rules": {
"exclude_from_discount": false,
"fee_label": "Fee",
"disp_hide_options_price": false,
"disp_show_section_price": false,
"disp_show_field_price": true,
"layout_option": "standard",
"pric_use_as_fee": false,
"process_fee_as": "woo_fee"
}
},
"fields": [
[
{
"type": "select",
"name": "select_86621060a3adce",
"label": "Include a message?",
"elementId": "select_86621060a3adce",
"value": [
{
"i": 0,
"value": "yes",
"label": "Yes, please",
"price": 0,
"weight": 0
}
],
"quantity": false,
"clStatus": "visible",
"price": false,
"weight": false,
"form_data": {
"name": "select_86621060a3adce",
"label": "Include a message?",
"enablePrice": false,
"price": "",
"active": true,
"required": true,
"elementId": "select_86621060a3adce"
},
"map_to_checkout": false,
"meta_id": 6613
},
{
"type": "textarea",
"name": "textarea_96621060a3adde",
"label": "Message",
"elementId": "textarea_96621060a3adde",
"value": "A lovely message.",
"quantity": false,
"clStatus": "visible",
"price": false,
"weight": false,
"form_data": {
"name": "textarea_96621060a3adde",
"label": "Message",
"value": "",
"enablePrice": false,
"price": "",
"active": true,
"required": true,
"elementId": "textarea_96621060a3adde"
},
"map_to_checkout": false,
"meta_id": 6614
}
]
]
}
}
},
{
"id": 6612,
"key": "Date",
"value": "2024-06-12",
"display_key": "Date",
"display_value": "12/06/2024"
},
{
"id": 6613,
"key": "Include a message?",
"value": "Yes, please | yes",
"display_key": "Include a message?",
"display_value": "Yes, please"
},
{
"id": 6614,
"key": "Message",
"value": "A lovely message.",
"display_key": "Message",
"display_value": "A lovely message."
},
{
"id": 6615,
"key": "_wcpa_order_meta_key_label_map",
"value": {
"6612": "Date",
"6613": "Include a message?",
"6614": "Message"
},
"display_key": "_wcpa_order_meta_key_label_map",
"display_value": {
"6612": "Date",
"6613": "Include a message?",
"6614": "Message"
}
}
],
"sku": "",
"price": 25,
"image": {
"id": 212,
"src": "https://domain.tldwp-content/uploads/2024/04/Serene.jpg"
},
"parent_name": "Serene"
}
],
"tax_lines": [
{
"id": 848,
"rate_code": "GB-VAT-1",
"rate_id": 1,
"label": "VAT",
"compound": false,
"tax_total": "21.00",
"shipping_tax_total": "2.50",
"rate_percent": 20,
"meta_data": []
}
],
"shipping_lines": [
{
"id": 847,
"method_title": "Nationwide Delivery",
"method_id": "szbd-shipping-method",
"instance_id": "4",
"total": "12.50",
"total_tax": "2.50",
"taxes": [
{
"id": 1,
"total": "2.5",
"subtotal": ""
}
],
"meta_data": [
{
"id": 6600,
"key": "Items",
"value": "Occasion Flowers - £96 × 1, Serene - White Tulips × 1",
"display_key": "Items",
"display_value": "Occasion Flowers - £96 × 1, Serene - White Tulips × 1"
}
]
}
],
"fee_lines": [],
"coupon_lines": [],
"refunds": [],
"payment_url": "https://domain.tldcheckout/order-pay/1154/?pay_for_order=true&key=wc_order_iODE9zHx1HFck",
"is_editable": false,
"needs_payment": false,
"needs_processing": true,
"date_created_gmt": "2024-05-31T11:08:06",
"date_modified_gmt": "2024-05-31T11:10:07",
"date_completed_gmt": null,
"date_paid_gmt": "2024-05-31T11:08:09",
"currency_symbol": "£",
"_links": {
"self": [
{
"href": "https://domain.tldwp-json/wc/v3/orders/1154"
}
],
"collection": [
{
"href": "https://domain.tldwp-json/wc/v3/orders"
}
]
}
}