Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce custom user input fields [closed]

I have a woocommerce store setup with 2 products that come in many variants, these are wristbands.

The customer is able to customise the product by selecting the colour, size, band type and they are able to add text to the band if they want to.

I have created a variable product with various dropdowns which is all good but I have come un-stuck trying to add a text field for the user to be able to write some text that is then saved and taken through the checkout field. The file that needs to be edited is: variable.php but I'm not sure how to achieve this.

I added a text field attribute to the variable product but this displays a dropdown on the front end and I don't want it to do that i need to display 2 text fields that take user input which is then saved.

I found this question: Woocommerce Custom Product Text which is quite similar to what I want to create.

I want to do this stuff in code without having to buy an add-on and I keep coming across solutions with plugins that need to be purchased. I just need a little help with this if anyone can that would be great as I have looked online for a couple of days now and I'm sure its not difficult I just need a little help. Thanks

like image 445
fnk Avatar asked Dec 03 '22 18:12

fnk


1 Answers

Adding this an answer so that other's might find it:

I'd strongly recommend saving yourself some time by simply purchasing the this plugin, it's only $49 dollars. However, if you really do want to figure this out for yourself; here's something to get you started. You'll need to hook into the following filters/actions:

  • woocommerce_before_add_to_cart_button (to add the fields to the form)
  • woocommerce_add_cart_item_data (to submit the field data)
  • woocommerce_get_cart_item_from_session (to add the data to the session)
  • woocommerce_get_item_data (to display the data on the cart page)
  • woocommerce_add_order_item_meta (to ad it to the order so it shows up in the admin area)
like image 109
Dre Avatar answered Dec 06 '22 10:12

Dre