• Hi

    We use custom template and include IF statements depending on the Order Status.

    We notice when the status is changed to completed and the email is sent, in the PDF it still shows IF results based on the old status. 2 minutes later when resending the email manually it works fine.

    For example, when a Processing order changed to Completed and Completed email is sent, it still shows UNPAID. 1-2 minutes later when resending it shows fine as PAID.

    <?php
    $status = $order->get_status();
    if($status == ‘completed’){
    echo “PAID”;
    } else {
    echo “UNPAID”;}
    ?>

    How can we fix this, so it picks up the live status? Downloading the PDF from Admin works fine instantly and there is no issues.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter 93bjones

    (@93bjones)

    Perhaps can we add a 2 minute delay before sending out the emails?

    Hi, since I am still a bit stuck with similar issue on pdf not updating live – I found out that the reason is probably cause somewhere along the way initial pdf was created (on new order, or processing).

    Try seeing if you have similar case to mine – in woocommerce orders list, if you press the pdf icon, as soon as the status is equal to the last one you want (completed), is the pdf ok?

    So, in other words maybe its this: if only one attach-to status is active, then only one pdf will get created?

    Thread Starter 93bjones

    (@93bjones)

    Pressing the PDF icon instantly after changes works fine. It’s just the email PDF attachment.

    2 minutes later resending the Email notification it works fine.

    Plugin Contributor Ewout

    (@pomegranate)

    I’m not sure if we can do anything about this from our end. The PDF invoice plugin does not send the email, this is entitely handled by WooCommerce. We merely hook into this process to add the attachment.

    When the order status is actually changed to the status you are after, depends on the way it is changed, which can be different ways depending on the payment gateway.

    Normally though, it should already have the actual status, as our plugin always loads the ‘latest’ order data. Here’s a quick rundown of the process when completing an order:

    1. $order->payment_complete() is called
    2. WC sets order status via $order->set_status() (source) which in turn triggers $order->status_transition() after saving
    3. the status transition triggers the woocommerce_order_status_{$status_transition['to']} hook which fires an additional hook from WooCommerce added here: woocommerce_order_status_{$status_transition['to']}_notification.
    4. Each of these _notification hooks can be used to trigger an email, such as here: woocommerce_order_status_completed_notification
    5. Our plugin then hooks into the attachment process of that email, using the woocommerce_email_attachments filter (source)
    6. This filter gets the current/most up to date order object, but because order meta may not be fully up to date at that point (order status always will be!) because this may have been updated by other processes hooking into the same hook,
      our plugin actively reloads the order object: we pass the order_id (here) rather than the order object, which triggers a reload.

    It should be clear from this rundown that under normal circumstances, our plugin hooks in way after the order is completed and always contains the latest available order data, but as I said, it’s possible that gateways have a different flow and confirm the order in two separate steps.

    Hope that helps!

    Plugin Contributor Ewout

    (@pomegranate)

    p.s. note that most gateways use ‘processing’ for the completed status. If you have anything autocompleting orders after this, that may be what you’re running into here. In that case you may be better off calling $order->is_paid() which returns true for both completed and processing

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Order Status Change’ is closed to new replies.