What I’ve ended up doing is at the DB level using the following queries
UPDATE DBNEW.wp_2_postmeta AS UPM3 SET meta_value = (
SELECT T3.meta_value FROM (
SELECT OL.new, PM.meta_key, PM.meta_value FROM DBLINK.order_links_old_new OL
LEFT JOIN DBOLD.wp_zx4bcbthfw_postmeta PM ON PM.post_id = OL.old
WHERE PM.meta_key LIKE '_cart_discount'
) AS T3 WHERE T3.new = UPM3.post_id
) WHERE UPM3.meta_key = '_cart_discount';
UPDATE DBNEW.wp_2_postmeta AS UPM3 SET meta_value = (
SELECT T3.meta_value FROM (
SELECT OL.new, PM.meta_key, PM.meta_value FROM DBLINK.order_links_old_new OL
LEFT JOIN DBOLD.wp_zx4bcbthfw_postmeta PM ON PM.post_id = OL.old
WHERE PM.meta_key LIKE '_order_total'
) AS T3 WHERE T3.new = UPM3.post_id
) WHERE UPM3.meta_key = '_order_total';
Obviously this is not ideal or a great idea, but it seems to have worked at least for display totals. Order Refunds will be a whole new amount of fun…
Correct, coupon discounts aren’t applied when adding an order from the API, just like they aren’t applied when manually creating an order in the WordPress admin.
More info: https://github.com/woothemes/woocommerce/issues/11358
Thanks, it’s the weirdest business logic I’ve ever seen, but now I’m aware
It’s more-or-less because of the way coupons work and have been developed. They get applied and calculated during the checkout process, but there is no way to use them in the admin screen / through the api and have them affect the total. As an admin, you have control over the total though, so you can apply the coupon manually.
Sure, I understand what is at the low-level the _cart_discount
field is created when adding via API though. It’s not exactly like the field cannot be altered or is not created structurally at a low-level (data-storage) the field exists. It can probably be altered using the existing WordPress-REST-API if someone does not want to go poking around in the DB, I was already in the DB because of the limitation with the order creation dates, I’ll likely be back there for order notes…