• Resolved stephenlimevalley

    (@stephenlimevalley)


    i currently need to use the wc_get_order() to get order data when a user submits an order. used this hook with the add action “woocommerce_checkout_order_processed” but the order data would not display. If i try echoing just the wc_get_order() hook it displays the boolean false. even if a pass a current order id in the code it still display false what is happening and how would i fix ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter stephenlimevalley

    (@stephenlimevalley)

    where do you get this data from “$order_id, $posted_data, $order” does wordpress pass this globally or is this something i have to pass my self ?

    Hi @stephenlimevalley,

    Thank you for contacting WooCommerce Plugin Support. I understand that you are having trouble with the wc_get_order() function and the woocommerce_checkout_order_processed hook. I’m sorry for the inconvenience this may have caused you.

    There are a few possible reasons why the wc_get_order() function may return false:

    • The order ID is invalid or does not exist.
    • The order status is not completed or processing.
    • The order object is not accessible or readable by the current user or role.

    To troubleshoot this issue, please try the following steps:

    • Make sure that you are using the latest version of WooCommerce and WordPress.
    • Check if the order ID is valid and exists in the database. You can use the wc_get_order_id_by_order_key() function to get the order ID from the order key, which is passed as a parameter to the woocommerce_checkout_order_processed hook.
    • Check if the order status is completed or processing. You can use the wc_get_order_status_name() function to get the order status name from the order ID.
    • Check if the order object is accessible or readable by the current user or role. You can use the wc_get_order() function to get the order object from the order ID, and then use the is_readable() method to check if the order object is readable.

    If none of these steps resolve your issue, please provide me with the following information:

    • A copy of your code where you use the wc_get_order() function and the woocommerce_checkout_order_processed hook.
    • A screenshot of the error or the output you get when you echo the wc_get_order() function.
    • The WooCommerce System Status Report, which you can generate from WooCommerce > Status > Get system report.

    I hope this helps you to solve the issue. Please let us know if you have any questions.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Issue with WooCommerce Hooks’ is closed to new replies.