Following my previous question "
Save WooCommerce order item custom fields sum as a new meta data", when an order is placed, some order item custom meta data quantity
, assemblycost
and calculated_field
(which value is to quantity
x assemblycost
) are saved.
How can I save as custom order meta data the sum of all order items calculated_field
values?
For example, a sample order would look like so:
Product A:
assemblycost: 10
quantity: 2
calculated_field: 20
Product B:
assemblycost: 15
quantity: 2
calculated_field: 30
Product C:
no assemblycost, quanity or calculated_field - custom fields present.
Product D:
assemblycost: 30
quantity: 2
calculated_field: 60
I want to create a new custom field for the order sum_calculated_fields
, and set this equal to the sum of the calculated_fields
in the order, so in the above example it would equal:
20+30+60 = 110.