Skip Navigation

[Resolved] the data (_product_attributes) are not saved

This support ticket is created 6 years 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 cherifM 6 years ago.

Assisted by: Nigel.

Author
Posts
#1156041
Capture d’écran 2018-11-30 à 09.21.49.png

Hello,

I added an generic fields but after the validation of the form the data are not registered in the product sheet (attributes)

[cred_generic_field type='select' field='Condition_gn']
{
"required":0,
"default":[""],
"options":[{"value":"","label":"None"},{"value":"as-good-as-new","label":"As good as new"},{"value":"good-normal-traces-of-use","label":"Good – Normal traces of use"},{"value":"in-its-own-element","label":"In it’s own element"},{"value":"need-to-be-restored","label":"Need to be restored"},{"value":"new","label":"New"},{"value":"very-good-no-defect-but-may-show-slight-traces-of-use","label":"Very good – no defect but may show slight traces of use"}]
}
[/cred_generic_field]

///////////////// function.php
add_action('cred_save_data', 'custom_function',10,2);
function custom_function($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==xxx)

{
$vals= isset( $_POST["Condition_gn"] ) ? $_POST["Condition_gn"] : array();
foreach($vals as $val) {
add_post_meta($post_id, 'wpcf-condition', $val, false);
}
}
}

Best regards
Mohammed

#1156158

I tested this code but it does not work; (

add_action('cred_save_data', 'set_parent_tutor_term_from_child',100,2);

function set_parent_tutor_term_from_child($post_id, $form_data) {
if ($form_data['id']==xxx)
{
wp_set_object_terms( $post_id, 'new', 'condition', true );
}
}

#1156190

Nigel
Supporter

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

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

Hi

Can I check what you are trying to do?

You have a form to publish WC products, is that it?

And you are trying to set product attributes for the published product?

WooCommerce stores the attribute details both as post_meta and as a custom taxonomy, and you would need to update both.

Here's an article describing how the data are stored: hidden link

#1156207

Hi Nigel,
nNo I created a list via the option "Add Generic Fields to the Form" and I wanted after the sumission of the form associate this list to the Attribute Product

Best regards
Mohammed

#1156293

Nigel
Supporter

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

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

Sorry, I'm not sure I understand.

When you talk about product attributes, do you mean standard WooCommerce product attributes, or is that a coincidence and you created something else with the same name?

Because if these are standard WC product attributes, then you need to manually set the post meta and taxonomies for product attributes based upon what is submitted in the form. You'll need to make sure they are stored in the correct format, which that linked article describes.

Here is another article which describes programmatically setting product attributes, which you could adapt to work with the Forms API hooks: hidden link

If that's not something you are comfortable doing you could enlist the help of a developer who is able to write PHP using the Forms API: https://toolset.com/contractors/

#1156365
form.jpg

Hi,

Sorry if I didn't express me very well.
In attachment you will find an illustration of what I meant.

Best regard
Mohammed

#1156397

Nigel
Supporter

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

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

Yes, so you are describing WooCommerce product attributes.

Toolset Forms don't have support for WC product attributes, if you want to publish products and set product attributes this is something you need to do yourself, which you can use the Toolset Forms API for, but which requires custom code.

Our support policy doesn't include writing such custom code.

I've given you some links which should prove helpful in coding this, but if it is not something you are comfortable with you will need to seek the help of a developer.

#1156398

My issue is resolved now. Thank you!