Title: Adding fields via code
Last modified: December 18, 2024

---

# Adding fields via code

 *  Resolved [rodsn](https://wordpress.org/support/users/rodsn/)
 * (@rodsn)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/adding-fields-via-code/)
 * Hello! I am trying to add items to the cart with the custom fields that have 
   been selected in a custom form i made. So far i have been able to add the product
   to the cart and even change the price (although i think my approach is not the
   best, as I’m using woocommerce_before_calculate_totals), but i can’t seem to 
   add the meta data to display the selected options bellow the item title.
   Is there
   a way to do this properly? This is urgent as the deadline nears and i have not
   yet been able to do this… Thank you in advance!
    -  This topic was modified 1 year, 5 months ago by [rodsn](https://wordpress.org/support/users/rodsn/).

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

 *  Plugin Author [Wombat Plugins](https://wordpress.org/support/users/maartenbelmans/)
 * (@maartenbelmans)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/adding-fields-via-code/#post-18205840)
 * Hi [@rodsn](https://wordpress.org/support/users/rodsn/),
   Our plugin is already
   a “form builder” so I’m not sure I understand the use case. 🙂 Can you explain
   why it needs to be a custom form rather than what WooCommerce supplies?
 *  Thread Starter [rodsn](https://wordpress.org/support/users/rodsn/)
 * (@rodsn)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/adding-fields-via-code/#post-18205897)
 * Hey Maarten!
   We have decided to use Elementor forms to handle the submissions,
   because we need all the fields it offers and because the clients are used to 
   making forms with Elementor. I made a custom field type for the Elementor form
   that lists all of the products so the user can select the ones they want and 
   then proceed to checkout.
 * We run the code bellow for every selected product, and it successfully adds it
   to the cart. Now the only thing left to do is to change the meta data and price
   just like your plugin does when i buy it through the product page.
 * `$key = WC()->cart->add_to_cart($product_id, 1, 0);`
    -  This reply was modified 1 year, 5 months ago by [rodsn](https://wordpress.org/support/users/rodsn/).
    -  This reply was modified 1 year, 5 months ago by [rodsn](https://wordpress.org/support/users/rodsn/).
 *  Plugin Author [Wombat Plugins](https://wordpress.org/support/users/maartenbelmans/)
 * (@maartenbelmans)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/adding-fields-via-code/#post-18206023)
 * Hi [@rodsn](https://wordpress.org/support/users/rodsn/) 
   Thanks for explaining!
   This approach could lock your client in, as they’d need custom coding to map 
   form inputs to price changes. If they want to update the form or add new fields,
   they’d have to modify the custom code.To do this securely, you’d need to hook
   into the entire add-to-cart process, from validation to checkout to order creation.
   Unfortunately, we can’t assist with this, as it’s outside the scope of our plugin.
   Good luck!
 *  Plugin Author [Wombat Plugins](https://wordpress.org/support/users/maartenbelmans/)
 * (@maartenbelmans)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/adding-fields-via-code/#post-18206034)
 * To add to my previous comment: note that some standard WooCommerce features like“
   order again” will not work properly anymore if you custom-code this without taking
   all those features into account.

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

The topic ‘Adding fields via code’ is closed to new replies.

 * ![](https://ps.w.org/advanced-product-fields-for-woocommerce/assets/icon-256x256.
   gif?rev=3347990)
 * [Advanced Product Fields (Product Addons) for WooCommerce](https://wordpress.org/plugins/advanced-product-fields-for-woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/advanced-product-fields-for-woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/advanced-product-fields-for-woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/advanced-product-fields-for-woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/advanced-product-fields-for-woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/advanced-product-fields-for-woocommerce/reviews/)

## Tags

 * [cart](https://wordpress.org/support/topic-tag/cart/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [product](https://wordpress.org/support/topic-tag/product/)

 * 4 replies
 * 2 participants
 * Last reply from: [Wombat Plugins](https://wordpress.org/support/users/maartenbelmans/)
 * Last activity: [1 year, 5 months ago](https://wordpress.org/support/topic/adding-fields-via-code/#post-18206034)
 * Status: resolved