php - Woocommerce: how to wc_add_order_item_meta on woocommerce_add_to_cart hook? -


use case:

  1. user choose date product list , add product cart button
  2. woocommerce_add_to_cart trigger and
  3. the date append item meta wc_add_order_item_meta

    add_action( 'woocommerce_add_to_cart', 'add_event_date_meta',  10, 3 );  function add_event_date_meta($cart_item_key, $product_id, $quantity) {    $event_date = get_cart_item_event_date();    $result = wc_add_order_item_meta( $product_id, '_event_date', $event_date); } 

the $result valid id, no '_event_date' meta included in checkout cart item. there not understand properly? meta key should added cart item while recieved id of it, or?

thank helgatheviking , loictheaztec yours comments. solution found in helgatheviking's tutorial. searching for:

    /*      * add custom data cart item      * @param array $cart_item      * @param int $product_id      * @return array      */     function kia_add_cart_item_data( $cart_item, $product_id ){        if( isset( $_post['_custom_option'] ) ) {           $cart_item['custom_option'] = sanitize_text_field( $_post['_custom_option'] );        }        return $cart_item;     }     add_filter( 'woocommerce_add_cart_item_data', 'kia_add_cart_item_data', 10, 2 ); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -