I have defined two custom fields for my Woocommerce orders. I used WooCommerce Admin Custom Order Fields extension to create these two fields.
When I manually create an order (/wp-admin/post-new.php?post_type=shop_order), I can see those fields and I can successfully add data and save the order.
I would, however, like to automatically populate one of those fields in the code. I'm trying to use the following code to do find out the meta key to that custom field so I can use update_post_meta()
to populate it, but this does not give me anything when I run it:
add_action('woocommerce_process_shop_order_meta', 'process_offline_order', 10, 2);
function process_offline_order ($post_id, $post) {
echo '<pre>';
print_r(get_post_meta($post_id));
die();
}
The documentation to that extension tells me that I can use something like get_post_meta($post_id, '_wc_acof_2')
with 2 being the ID of that custom field and I tried that too with no luck. It's not returning anything.
Below is an screen shot of my configuration screen:
Any idea how I can access/populate those fields and what hook to use if the one I'm using is not correct?