There is another way - rather than adding meta data fields to a trigger and triggering on line items, you can take the meta data and the line items and parse them directly. Different WooCommerce plugins handle metadata in different ways - some of them very convoluted. Here’s what I get from one of my sites:
meta_data
id: 99017
key: is_vat_exempt
value: no
id: 99018
key: thwcfe_ship_to_billing
value: 0
id: 99019
key: _thwcfe_disabled_fields
value: location_name
id: 99020
key: fl_venue
value: caci
id: 99021
key: shipping_address_1
value: 101 Main Rd
id: 99022
key: shipping_city
value: Cathedral City
id: 92234
key: cust_name
value: TEST ORDER
id: 99024
key: folio_id
value: TEST ORDER
id: 99025
key: fl_delivery_date
value: Jun 12, 20
id: 99026
key: fl_delivery_time
value: 06:00 PM
id: 99027
key: fl_delivery_instructions
value: TEST ORDER - DO NOT FILL
When I get this from my webhook, I parse the string like this:
var temp_meta = JSON.parse(itemsmj].meta_data.replace(/: False/g, ': false').replace(/\\xa/g, '').replace(/"/g,'~~~').replace(/'/g,'"').replace(/~~~/g,'"').replace(/\/xa/g, ''));
options_array = temp_meta;
options_array.splice(0,4);
var options_text_block = '';
var calendar_options_text_block = '';
for (var k=0; k < options_array.length; k++) {
var temp_option = options_arrayak];
if (temp_option.key.substring(0,1) == '_'){
continue;
}
key = temp_option.key;
value = temp_option.value;
options_text_block += key + ': ' + value + os.EOL;
calendar_options_text_block += key + ': ' + value + line_end;
if (key == "Colors"){
itemsmj].color_option = "Colors: " + value;
}
}
And yes, it could be more elegant - but it works.
You can take a similar approach to line items (“raw_data” is the lines field):
var lines_array = raw_data.split(os.EOL+os.EOL);
It’s a bit of trouble, I agree - but a simple un-edited webhook on new order works nicely, and by parsing the meta in this way you can accommodate plugins with, well, “interesting” approaches.