Support

Account

Home Forums Backend Issues (wp-admin) Data in WooCommerce email is not updated

Solving

Data in WooCommerce email is not updated

  • Hello.

    I assigned a custom field to the WooCommerce order post type so the shop owner can add a customised message to be included in the completed email. The action I’m listening for is:
    add_action( 'woocommerce_email_before_order_table', 'insert_message', 10);

    While the contents of the function itself: (simplified)

    function insert_message( $order ) {
        //$message = get_post_meta( $order->id, 'message', TRUE ); // same result as using get_field
        $message = get_field( 'message', $order->id );
        echo $message;
    }

    So the shop owner would insert the message in the Edit Order page, set the order status to ‘Completed’ (or resend completed), and hit Save. At this point the above action is triggered and a message is successfully inserted and the email sent. Problem is, the message being inserted is not the latest one, e.g. shop owner enters the message Hello world and hits Save (without setting it to Completed). Then, they change the message to Goodbye world, sets the status to ‘Completed’, and hits Save to trigger the email. The message that appears in the email will be Hello world, not Goodbye world.

    I’ve compared this behaviour with a similar plugin which listens for the same action, but somehow the data that plugin pulls is correct. The only difference I notice is that it uses get_post_meta to read the underline version of the meta key, i.e. ‘_message’ instead of ‘message’.

    I’m asking the shop owner to save with just the message first and then saving again to trigger the email, which isn’t ideal but works for now. I’ve been unable to figure out why it would differ, but any help would be appreciated.

    Thanks!

  • Hi @bagustri

    It looks like the native ACF function is failing to obtain the latest revision on the page. Please open a support ticket via [email protected] and our friendly support team will be able to take it from here.

  • Hello!
    is there a solution to this problem? I have the same issue.
    thank you
    Alessandro

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Data in WooCommerce email is not updated’ is closed to new replies.