1

I am working on building a custom integration from WooCommerce to our internal ERP. I hooked into the woocommerce_checkout_order_processed so that when an order is placed I send all relevant information to our ERP and the reply is an order ID. This is a different order ID than what is in WooCommerce and I need a way to map the ERP order ID to the WooCommerce order. What is the best way to accomplish this?

I have tried adding custom metadata, but so far that has failed. add_metadata( "shop_order", $order->id, "mapics_order", (string) $orderNumber, TRUE ); and am trying to avoid using wc_add_order_item_meta since this is not item specific, but for the entire order itself.

1 Answer 1

3

you can use woocommerce_checkout_update_order_meta hook to update order meta. Please check sample code

add_action('woocommerce_checkout_update_order_meta', 'custom_checkout_field_update_order_meta');

function custom_checkout_field_update_order_meta($order_id)
{
    session_start();
    if ($_SESSION['mapics_order'])
        update_post_meta($order_id, 'mapics_order', esc_attr(htmlspecialchars($_SESSION['mapics_order'])));
}
3
  • Awesome, thank you! I stripped it down to just update_post_meta which seems to be working fine, but I will need to do some checks to be sure.
    – fwho
    Jun 14, 2017 at 13:02
  • sessions? are they still allowed in php? ;) more seriously, where does exactly the data supposed to get into the session? Jun 14, 2017 at 13:14
  • 1
    Passing data into a session is easy, and even if its not a perfect answer it gave me the missing piece that I needed to continue my project.
    – fwho
    Jun 14, 2017 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.