4

I am creating a plugin where I am using woocommerce_checkout_update_order_meta hook to add order item meta.

I have a plugin called WooCommerce TM Extra Product Options installed.
This plugin uses woocommerce_checkout_create_order_line_item hook to add order item meta.

When the plugin is activated, I am getting the plugin's meta fields displayed on the order received page but my meta information is not getting displayed. My meta is getting displayed if the plugin is deactivated or when I comment the woocommerce_checkout_create_order_line_item action hook.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Rashmi M
  • 83
  • 1
  • 3
  • 6
  • You could give the code of your custom plugin hooked in woocommerce_checkout_update_order_meta in your question… It should help to understand better your issue. – LoicTheAztec Jan 17 '18 at 00:40

1 Answers1

10

They are not really for the same things:

  • The hook woocommerce_checkout_update_order_meta allow for example to add / update the Order meta data so the database table wp_postmeta.
  • The hook woocommerce_checkout_create_order_line_item allow for example to add / update line items type in the Order so in database tables wp_woocommerce_order_items (for line_item item type (product name)) and in wp_woocommerce_order_itemmeta (for line_item item type details as quantity, line item totals and attributes for product variation, attributes…).

For the priority (there is not really a priority as they are not made for similar things):

To add order item meta, you should better use woocommerce_checkout_create_order_line_item action hook instead with priority before the WooCommerce TM Extra Product Options plugin.

Example:

add_action( 'woocommerce_checkout_create_order_line_item', 'custom_checkout_create_order_line_item', 20, 4 );  
function custom_checkout_create_order_line_item( $item ) {  
   $item->add_meta_data( 'meta_key', 'meta_value' );  
}

Related: WooCommerce: add different order item meta for each item in order

Andy
  • 4,783
  • 2
  • 26
  • 51
LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Hello I am using woocommerce_checkout_create_order_line_item hook to add meta with key name as extra_charge , is it possible to show the key name as Extra Charge – inrsaurabh Jul 30 '18 at 08:59