Title: Add Field Value Programmatically
Last modified: June 1, 2021

---

# Add Field Value Programmatically

 *  Resolved [reshampanth](https://wordpress.org/support/users/reshampanth/)
 * (@reshampanth)
 * [5 years ago](https://wordpress.org/support/topic/add-field-value-programmatically/)
 * Hi,
    I’m creating a product for which I need an additional text field. The value
   of this field will be defined by the customer’s actions prior to clicking on 
   the Add TO Cart link. The Customer will provide two values prior and based on
   those values, I have to add the appropriate product to cart directly using Woocommerce
   hooks WC()->cart->add_to_cart( 1326 ) My first question is, how do I set the 
   value for the additional field manually before adding the product to cart? My
   second question is, how do I display this in the Cart and Checkout page? Will
   the field automatically show up along with the cart information? Will it work
   with Oxygen Builder?
 * Thanks in Advance!

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Support [Acowebs Support Team](https://wordpress.org/support/users/ashwinacodez/)
 * (@ashwinacodez)
 * [5 years ago](https://wordpress.org/support/topic/add-field-value-programmatically/#post-14518929)
 * Hi,
 * As per your requirement, what we understand is you need to add a product to the
   cart programmatically once a button is pressed. For this you can’t access our
   plugin classes directly, instead, you have to follow one Woocommerce filter hook**
   woocommerce_add_cart_item_data**
 * woocommerce_add_cart_item_data hook will provide you the details added by our
   plugin and you can even alter its values.
 *     ```
       add_filter('woocommerce_add_cart_item_data', function($cart_item_data, $product_id, $variation_id)
       {
          //$cart_item_data you can check all custom field values in this variable 
          return $cart_item_data;
       }, 10, 3);
       ```
   
 * Hope this helps.
 * Thank you
    -  This reply was modified 5 years ago by [Acowebs Support Team](https://wordpress.org/support/users/ashwinacodez/).
 *  Thread Starter [reshampanth](https://wordpress.org/support/users/reshampanth/)
 * (@reshampanth)
 * [5 years ago](https://wordpress.org/support/topic/add-field-value-programmatically/#post-14519569)
 * Hi,
 * Thank you for your response! This is exactly the information I need!
 * I’ll try to implement this and will update the ticket if any issues come up 🙂
 * Cheers,
    Resham Panth

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Add Field Value Programmatically’ is closed to new replies.

 * ![](https://ps.w.org/woo-custom-product-addons/assets/icon-256x256.gif?rev=3328656)
 * [Product Addons for Woocommerce - Product Options with Custom Fields](https://wordpress.org/plugins/woo-custom-product-addons/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woo-custom-product-addons/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woo-custom-product-addons/)
 * [Active Topics](https://wordpress.org/support/plugin/woo-custom-product-addons/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woo-custom-product-addons/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woo-custom-product-addons/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [reshampanth](https://wordpress.org/support/users/reshampanth/)
 * Last activity: [5 years ago](https://wordpress.org/support/topic/add-field-value-programmatically/#post-14519569)
 * Status: resolved