I am trying to: add custom fields to a WooCommerce order
Link to a page where the issue can be seen: in development
I expected to see: the value as set in the form
Instead, I got: value not set
Issue: Toolset creates an intermediate post when making an order using Toolset Forms Commerce, but does not copy custom field values to the final order.
Plugins:
WooCommerce
Toolset Blocks
Toolset Forms
Toolset Forms Commerce
Toolset Types
Toolset WooCommerce Blocks
Steps
1. Add a custom field to WooCommerce orders: Go to Toolset > Dashboard > Orders > Add custom fields (for example 'City')
2. Create a post form: Toolset > Post Forms
3. Create the form:
> Post type to create/edit: Orders
> After visitors submit this form: Go to a page > Checkout
> In the form editor make sure the custom field has been added
> Under 'Toolset Forms Commerce' make sure 'Charge payment with this form' is checked
> Select a product
4. Create a WordPress page and add the form we just created
5. View the page and fill in the form
6. Submit the form
7. Go to WooCommerce > Orders. An intermediate order has been created. If you open the order you will see that the value for the custom field is displayed. Remember the post ID, for instance 1.
8. On the checkout page finalize payment (I have set this to COD (Pay with cash upon delivery).
9. Submit the checkout form
10. Go back to orders: another order has been created with ID 2. If you open the order you will see that the value for the custom field is no longer set. It seems it is not copied over from the intermediate post with ID 1.
> Post type to create/edit: Orders
Issue: Toolset creates an intermediate post when making an order using Toolset Forms Commerce, but does not copy custom field values to the final order.
Hi, I'm a bit confused about what you are trying to achieve here. In the normal workflow, you would not create WooCommerce Orders with Toolset Forms. WooCommerce will automatically create an Order post when the front-end user checks out, so that would result in 2 Orders if the Form is set to create Orders. Custom fields set in the Oder you create with Forms will not be copied over to the Order created by WooCommerce, that is not how the process is intended to work.
Can you explain a bit about what you want to accomplish? Normally Toolset's Forms Commerce is used to create a post or custom post type in "Draft" status. Then when the User checks out and completes payment for their Order, that draft post is automatically published. So Toolset Forms Commerce is an effective way to charge Users to post content on the site. However, in your example, the Form creates an Order post...not a post or custom post content for the front-end of the site. There is no additional post created or published, it's just an Order...for another Order? So it seems a bit unusual, and I'm confused about what you plan to accomplish here. Can you provide a few more details?
Hello Christian,
I am trying to add custom user input fields when someone purchases a product. The products are essentially appointments for medical tests. Depending upon the type of appointment I need the user to provide additional input. For example for some type of appointments the user needs to input a list of people that will attend the appointment and need to be tested.
The user input should be saved for each order. Each order only includes a single product.
Product A
=> Custom field date
Product B
=> Custom field date
=> Repeatable input field 'attendee'
Product C
=> Custom field date
=> Custom field checkbox yes/no
Initially I created a post type Appointment and tried to link that to the final Order. But this did not work out as I had foreseen. Therefore I am now trying to store all user input in the order. It is essential to setup the relationship between the Appointment (data) and the final Order as the latter contains important information for the appointment.
Additionally, because of privacy concerns, I need to make sure, only the current visitor (and any admins) can see the entered data.
Depending upon the type of appointment I need the user to provide additional input. For example for some type of appointments the user needs to input a list of people that will attend the appointment and need to be tested.
This sounds like it would be better accomplished with the WooCommerce Product Add-Ons package, or another 3rd-party tool that collects additional information about each Order depending on the Product purchased. Forms Commerce is not really ideal for what you want to achieve here, since the Forms Commerce process involves creating some post and charging to publish that post.
Initially I created a post type Appointment and tried to link that to the final Order. But this did not work out as I had foreseen.
This sounds more like what Forms Commerce is intended to provide. Is there something I can do to help make this process work better for your needs? What problems did you encounter in this approach?
Hello Christian, I reworked the second option using a CPT Appointment.
Making an appointment starting with a Forms Commerce form is being done in steps and Toolset does not support multi-step forms. Therefore I created pages for each step. To store the data for each step in the correct appointment, I needed a way to pass along the Appointment ID. Doing that via url parameters is not secure. I now use php sessions to pass along the Appointment ID.
That resolved a big issue.
Appointments have a relationship with WooCommerce Orders. Using the cred handler cred_commerce_after_payment_completed I connect both.
I think it would be a great addition to Toolset to get away from passing along variables via the URL and offer other options, like session data. This would open up possibilities like creating multi-step forms and an easier and more secure way to pass along data.
Yes I agree this session-based approach is more secure than a URL-parameter approach. We will consider your request to enhance the security of Forms with session-based storage, but given the current workload and other priorities I suspect a custom code solution like this will be required for the near future. If that changes I will be glad to update you here.
I think a session based approach is not only more secure. It also opens up possibilities that Toolset currently lacks and make it more competitive with the likes of JetEngine.