Thanks for the tutorial helped me a lot!! Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site I added a custom size into my dropdown, & when user selects it, the text field would show up. I tried adding a simple text variable and it worked, but storing an array like isnt. Company no: 11728325. I need a few clarifications from you 1. After this it is always adding the previous carts custom data. Calculate totals by looking at the contents of the order. You can thank us later. I tried to use your functions but nothing happend, any ideas? Alias for get_order_tax(). Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. please do reply. thanks, I do have some questions, I am very new to Woo Commerce and I dont know where to put all this code, I mean, functions.php? FooEvents for Woocommerce has a metafield WooCommerceEventsDate which I need to add to the line-item order meta for each line item in an order, Reason: Probably your problem is on step 5. So far I have, 1. P.S If you need any help with Woocommerce Customization or Development, feel free to Contact Us. ; } add_action( woocommerce_after_shop_loop_item, add_name_on_product_loop, 9 ); function add_name_on_tshirt_field( $cart_item_data, $product_id ) { if( isset( $_REQUEST[spicy_level] ) ) { $cart_item_data[ spicy_level ] = $_REQUEST[spicy_level]; /* below statement make sure every add to cart action as unique line item */ $cart_item_data[unique_key] = md5( microtime().rand() ); } return $cart_item_data; } add_action( woocommerce_before_add_to_cart_button, add_name_on_tshirt_field ); function tshirt_name_validation() { if ( empty( $_REQUEST[spicy_level] ) ) { wc_add_notice( __( Please enter a Name for Printing, woocommerce ), error ); return false; } return true; } add_action( woocommerce_add_to_cart_validation, tshirt_name_validation, 10, 3 ); function save_name_on_tshirt_field( $cart_item_data, $product_id ) { if( isset( $_REQUEST[spicy_level] ) ) { $cart_item_data[ spicy_level ] = $_REQUEST[spicy_level]; /* below statement make sure every add to cart action as unique line item */ $cart_item_data[unique_key] = md5( microtime().rand() ); } return $cart_item_data; } add_action( woocommerce_add_cart_item_data, save_name_on_tshirt_field, 10, 2 ); function render_meta_on_cart_and_checkout( $cart_data, $cart_item = null ) { $custom_items = array(); /* Woo 2.4.2 updates */ if( !empty( $cart_data ) ) { $custom_items = $cart_data; } if( isset( $cart_item[spicy_level] ) ) { $custom_items[] = array( name => Name On spicy_level, value => $cart_item[spicy_level] ); } return $custom_items; } add_filter( woocommerce_get_item_data, render_meta_on_cart_and_checkout, 10, 2 ); function tshirt_order_meta_handler( $item_id, $values, $cart_item_key ) { if( isset( $values[spicy_level] ) ) { wc_add_order_item_meta( $item_id, spicy_level, $values[spicy_level] ); } } add_action( woocommerce_add_order_item_meta, tshirt_order_meta_handler, 1, 3 ); Not working on my end. Now we have updated the wooCommerce version 2.9 to 3.6.2. jQuery(document).ready(function(){ jQuery(.single_add_to_cart_button).click(function(){ alert(sending ajax request); var user_data = user_data; var id = id; var ajaxurl = ; jQuery.ajax({ url: ajaxurl, type:POST, data: { action:wdm_add_user_custom_data_options, user_data : user_data, id : id. Magic __get method for backwards compatibility. You'll see that the function includes two ways to get metadata - first, to iterate through all metadata in each line item. 'created_via' => '', Thanks so much for this post it is quite literally exactly what Ive been searching for. moreover, I will never make any update in plugin or theme or anywhere else, so its not the problem for me if I do any changes in core Woocommerce files, so can you please suggest me how to make changes in core woocommerce file and what code need to be added and where? I just need this, but i cant make it work, im trying other approach because i dont have any custom field, i just want to add just some custom data. For those of you who have worked with WooCommerce might know that on the click of the Add to Cart button the product page gets refreshed and the user data is lost. Alias of WC_Order::get_shipping_total(). Is that not a standard Woocommerce hook? classes. first time i am not getting the data on cart but second time it did whats the issue. Will use the base country unless customer addresses are set. $product = $item-> get_product(); Other steps work with foreach inside, no magic. It was showing nothing.. on cart or on order window in woocomerce.. Hi, this is exactly what I am looking! Ive added additional function to functions.php in same location as step one. Adds an order item to this order. For your requirement you need to find a hook which unsets the WooCommerce session data if only one item is removed from the cart. Really Awesome tutorial! Do you want to apply WooCommerce get order meta_data in your WooCommerce development but you cannot figure out how to get the WooCommerce order meta data? Is there a weapon that has the heavy property and the finesse property (or could this be obtained)? All rights reserved. Apparently theres not a WC session initiated outside any non WooCommerce page and thats how you get this issue. Should this work for guest too? Get's the URL to edit the order in the backend. Thanks for your answer!, that script is for add products to the cart, and it works. Because of this, I needed to make sure the session was unset after it was used. Thank you very much for answering my questions. it will be a huge help if you give me solution for this . Manual discounts are not affected; those are separate and do not affect 'date_paid' => So we have planned to use your source code written for WooCommerce version above 3.0 (https://wisdmlabs.com/blog/add-custom-data-woocommerce-order-2/) and we have faced an issue with woocommerce_before_add_to_cart_button hook. Ive added the codes to the function.php file of my theme. It will also be used in the confirmation email that is sent to the user after a payment is made. 2. Here's the code for reference: When I look at the database, it's being created, and the order_item_id matches the order_item_id for shipping on that order, so that all is working fine (and I can see it displayed on the backend order display view). I added before the add-to-cart-button the following field that need to be placed into the order: Do Guppies Poop A Lot Before Giving Birth, Nick Dunlap Fullerton Political Party, Shimano Fishing Uk Contact Email, Articles W