Skip Navigation

[Resolved] Frontend prodct form doesn't insert any price in db

This support ticket is created 3 years, 12 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 7 replies, has 2 voices.

Last updated by giuseppeU 3 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#1906271

In frontend add-product form, when I try to insert a product, the form sends all the data correctly except the Woocommerce price. Although this field is filled in, it is not saved in the db. Why?
The page is: hidden link

#1906639

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

The reason the price isn't updated is that the field you added to your product form isn't the actual WC price field, it is a special field registered by Toolset for internal purposes, and so your form has set the value for that field rather than the actual price field.

The reason the actual price field isn't available is because it is a hidden custom field (WC registers the price field with a key of _price; the underscore means it is a hidden rather than public custom field).

You can include this is in your form, but it will involve switching to Expert mode for it to work. Once you switch to expert mode you can't switch back without losing changes, so just to be on the safe side, you might want to duplicate your original form and work on the copy for testing.

Before switching to Expert Mode, from the right hand side drag a numeric generic field into your form where you want it to be shown.

Set the field slug to be "_price", and label the field (e.g. "Price").

There is an additional setting required for this field for it to be saved (normally generic fields are discarded after submission), but it can only be added in Expert mode, so switch mode now.

Locate the markup where this field is inserted and edit it to add a setting "persist":1 like so:

	<div class="form-group">
	<label>[cred_i18n name='generic-filed-_price-label']WC Price[/cred_i18n]</label>
	[cred_generic_field type='numeric' field='_price']
{
"required":0,
"default":"",
"persist":1
}
[/cred_generic_field]
	</div>

Save your form and test on the front-end. You should now find that the price is correctly set.

The next dev cycle will be focused on improvements to the WooCommerce integration, and I expect this is one area we will look at.

#1906899

Thak you, Nigel, it's perfect, but I have a new question about this.
Is it possible to keep the data entered in the form in an email addressed to the administrator? This would make it easier not to lose user data

#1909319

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You can set up form notifications to email the site admin when the form is submitted, as described here: https://toolset.com/course-lesson/send-notifications-when-someone-submits-the-form/

You can use the Fields and Views button to insert shortcodes for fields from the form that will be replaced by the submitted values.

For generic fields, as discussed above, you can insert the Post Field shortcode, so you would output the submitted price with

[wpv-post-field name="_price"]
#1912339

My issue is resolved now. Thank you! Good job!

#1914133
frontend_email_input.jpg
frontend_email_output.jpg

Sorry, but when I create a form to add a product via the frontend I am faced with two problems that I still can't solve.
The first problem relates to the email to the administration and shows the summary data of the form.
I used this shortcode, suggested by you
[wpv-post-field name = "_ price"]
to fill in the email fields, as you can see in attached image (_INPUT). But the email only shows the price (_OUTPUT), while all the other fields are empty. In the dashboard, however, the data is entered correctly, apart from the attributes.
And this is the second problem. Why are attributes not stored?

#1914319

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

The wpv-post-field shortcode is only intended to output raw values of non-Types custom fields. For anything else, you should use the Fields and Views button to insert the shortcode for the field you require. (For standard fields that will insert dedicated shortcodes such as wpv-post-title, for custom fields it will insert a types shortcode.)

As this is marked as resolved, if you have further problems, could you please open a new thread?

#1914419

It works fine! Thank you!