WordPress.org

Forums

WooCommerce - excelling eCommerce
How to hook add to cart event to add custom data? (4 posts)

  1. azharpratama
    Member
    Posted 1 year ago #

    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.

    http://wordpress.org/plugins/woocommerce/

  2. Roy Ho
    Member
    Posted 1 year ago #

    Perhaps you want to use this hook instead:

    do_action( 'woocommerce_add_order_item_meta', $item_id, $values );
  3. IgniteWoo Team
    Member
    Posted 1 year ago #

    You need to use anywhere from 2 to 7 different hooks depending on what all you want to accomplish overall.

    Look into these hooks:

    woocommerce_add_cart_item_data
    woocommerce_get_cart_item_from_session
    woocommerce_get_item_data
    woocommerce_add_to_cart_validation
    woocommerce_add_cart_item
    woocommerce_checkout_update_order_meta
    woocommerce_order_item_meta

  4. N-Media
    Member
    Posted 7 months ago #

    Hi,

    If you don't want create new plugin and add these all hooks, please use this plugin instead:

    Personalized product meta

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic