替換已折衷的“ woocommerce_add_order_item_meta”中的woocommerce
中的“ woocommerce_add_oder_item_item_meta” hook hook hook in woocommerce
Replacement Hook: woocommerce_checkout_create_order_line_item
Since WooCommerce 3, a new CRUD (Create, Read, Update, Delete) system has been introduced, which includes new固定器和Getters方法。 “ wooocommerce_add_order_item_meta”的替換掛鉤是參數:
$ item:new Wc_order_item_product class
object
Usage of woocommerce_checkout_create_order_line_item:
To add custom meta to order items using this hook, you can use the following updated code:
add_action( 'woocommerce_checkout_create_order_line_item','custom_checkout_create_order_line_item',20,4);
函數custic_checkout_create_order_line_item($ item,$ cart_item_key,$ values,$ order){
//使用WC_DATA UPDATE_META_DATA()方法更新訂單項元
$ item-> update_meta_data('meta_key1',$ custom_field_value);
} -
,而wooocommerce_checkout_create_create_order_item_item掛鉤是推薦的替換,您仍然可以使用已折磨的“ Woocommerce_add_odd_order_item_etem_meta” hooks nook offected'但是,重要的是要注意,此鉤被棄用,並可以在WooCommerce的未來版本中刪除。 -
函數custic_add_order_item_meta($ item_id,$ values,$ cart_item_key){
//使用WC_ADD_ORDER_ITEM_META()更新訂單元件元件
wc_add_order_item_meta($ item_id,'meta_key1',$ custom_field_value);
} - condusion [&& && && && &&華氏度[&& && && woocommerce_checkout_create_create_order_order_item_item hook是推薦的替換deftacement“ WooCommerce_Addd_Ordem_Item_item_Metem_meta” Hook時使用WOOCOMERCER_EDEM_ITEM_METEM_META“在使用WOOCommerce時,它提供了相同的功能並與該版本中介紹的新CRUD系統保持一致。