How to hook add to cart event to add custom data?
-
Hello,
I’m trying to add some custom meta data to order item of WC in order to store custom product data generated by a plugin from front-end. The goal is to display the data on admin order page. Here’s my code so far:
add_action( 'wp_ajax_woocommerce_add_to_cart', 'add_custom_product_meta' ); add_action( 'wp_ajax_nopriv_woocommerce_add_to_cart', 'add_custom_product_meta' ); function add_custom_product_meta( $item_id ) { global $woocommerce, $wpdb; if ( $item_id ) { woocommerce_add_order_item_meta( $item_id, '_custom', 'test' ); } }
Any help would be very nice. Thanks.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘How to hook add to cart event to add custom data?’ is closed to new replies.