What i am trying to do is to make order programatically and then hook on it's data to pass info to the api, like this:
function make_custom_order() {
$order = wc_create_order();
$order->add_product( wc_get_product( $product_id ), 1 );
$order->set_address( $order_info, 'billing' );
$order->calculate_totals();
$order->update_status('pending');
update_post_meta($order->get_id(), 'offer_id', $offer_id);
update_post_meta($order->get_id(), 'country_code', $country_code);
update_post_meta($order->get_id(), 'price', $price);
update_post_meta($order->get_id(), 'lander', $lander);
update_post_meta($order->get_id(), 'ip', $ip);
update_post_meta($order->get_id(), 'referrer', $referrer);
update_post_meta($order->get_id(), 'device', $device);
update_post_meta($order->get_id(), 'product_id', $product_id);
update_post_meta($order->get_id(), 'network', 'somenetwork');
}
add_action( 'woocommerce_checkout_process', 'make_custom_order' );
This works and the order is created, now for the 3rd party API part, i am using this function:
add_action( 'woocommerce_new_order', 'send_to_api' );
function send_to_api( $order_id ) {
echo get_post_meta( $order_id, 'device', true );
}
However i have noticed that woocommerce_new_order is fired before the metadata is saved and i cannot get the metadata to send to 3rd party API.
Does anyone know how to hook on new order after all custom fields metadata is saved?
Thanks