Display and save added custom cart item data on Woocommerce Cart, Checkout and Orders

前端 未结 3 705
北恋
北恋 2021-01-22 04:51

I am trying to add product in cart with cart item meta data. Here is the code :

$cart_item_data = array();

$cart_item_data[\'add_size\'] = array(\'PR CODE\'=>         


        
3条回答
  •  悲&欢浪女
    2021-01-22 05:03

    After I spent the last hours figuring things out I found out that the method has actually changed a bit over the time.

    Method:

    $woocommerce->cart->add_to_cart( $product_id, $quantity, $variation_id, $variation, $cart_item_data );
    

    In my case I needed to do this and the custom meta data got automatically displayed in the cart and order:

    $woocommerce->cart->add_to_cart($product_id, $quantity, NULL, NULL, array('your_key' => 'your_value'));
    

    You can find out more here: https://woocommerce.wp-a2z.org/oik_api/wc_cartadd_to_cart/

提交回复
热议问题