Skip Navigation

[Resolved] Default Values for Custom Fields

This support ticket is created 3 years, 10 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 8 replies, has 2 voices.

Last updated by mandeepD 3 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#2338839
Screen Shot 2022-04-11 at 8.49.23 PM.png

We have created a field group for WooCommerce products and set default values for each. The idea is to have these default values display for products of the same category without editing products individually.

However, the field values are not displayed in the front-end unless we go into each product and click on the update button.

We are using the types_render_field method in PHP to do this in the WooCommerce template. Is there any way for us to display the default values of these fields without going through a tedious process? We have hundreds of products on our site.

#2338937

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mandeep,

Thank you for getting in touch.

Actually this behaviour is expected because the fields have not yet be set for the post until that post has been saved or updated.

Essentially the fields are just displaying but nothing has been st to the database as yet.

I hope this clarifies your issue for you.

Thanks,
Shane

#2338959

Can you recommend a way for us to bypass that and perhaps do it programatically, rather than going into individual products and updating them?

#2338987

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

This can be done by using custom coding to go through and update all your posts but this is not something that I can assist with since it is essentially out of the scope of our support forum.

Thanks,
Shane

#2339579

I see. From another angle, is there a way for us to pull the default value set for a custom field in a field group itself? Not the meta value from a specific post.

#2339723

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Not necessarily to pull the default value but you do have the option to check if the field is empty using the conditional block and then display some default text.

Using our conditional block it is possible to check if the field has a value assigned. This means that any post that you haven't updated will return an empty value for the custom field.

In that case when the field is empty you can specify some text to display should the empty field triggers the conditional.

Please let me know if this helps.
Thanks,
Shane

#2340359

The main goal is actually to have the default values for those custom fields manageable in the WordPress admin and be displayed in the product page for all products under a certain category. There are hundreds of these and going into every single one and updating them manually is counter-productive. Only a few products may have different values.

Also, we are looking for a way that this can be managed by someone without programming knowledge, thus the WYSIWYG using toolset.

Are you saying that this can't be done?

#2340491

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mandeep,

Unfortunately no it cannot, given the limitations that wordpress provides where even custom fields with default values aren't set on a post until the post is updated.

What happens is that wordpress only provides an API to retrieve the custom field value from the postmeta table and this is what we use to get the value. The main issue is the default value for the field is stored in the options information for the custom field which is not publicly accessible via the wordpress API.

Essentially it comes down to your posts must be updated in order for the default value to be set for the post.

Thanks,
Shane

#2341783

Thanks for your help.