• It looks like when adding an order via the API the discount from coupons is not applied to the order.

    I have tried retrospectively adding the coupon to the order as well and this also did not work.

    It should be noted that the order is being added with status completed as it is technically a migration using the API to create the order from site A to site B.

    I also tried creating an order with status processing, still didn’t work 🙁

    WooCommerce 2.6.3, WordPress 4.5.3

    https://wordpress.org/plugins/woocommerce/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter LewisCowles

    (@lewiscowles)

    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…

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    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

    Thread Starter LewisCowles

    (@lewiscowles)

    Thanks, it’s the weirdest business logic I’ve ever seen, but now I’m aware

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    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.

    Thread Starter LewisCowles

    (@lewiscowles)

    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…

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    You can use the api for order notes 🙂 – http://woothemes.github.io/woocommerce-rest-api-docs/#order-notes

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Order discount not visible’ is closed to new replies.