Skip Navigation

[Resolved] Set regular price to default

This support ticket is created 2 years, 4 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 24 replies, has 2 voices.

Last updated by Shane 2 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#2424641

Hello,

This is already an answer on my request but I have additional questions:
1. Where can I find the original Form ID?
2. Must the parameter be Run on the Font-End?
3.Do I need the on-demand mode?
4. Must I use the toolset_snippet_security_check line?

Hello. Thank you for contacting the Toolset support.

There are couple of ways, to set regular price either you can add it as hidden field and set it's default value or you can use the Toolset Form's hook "cred_save_data" that will run after you submit the form.

For example - you should try to add the following code to "Custom Code" section offered by Toolset:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

1
2
3
4
5
6
7
function func_custom_update_product_regular_price($post_id, $form_data) {
// if a specific form
if ($form_data['id']==99999) {
update_post_meta($post_id,'_regular_price', 1111);
}
}
add_action('cred_save_data', 'func_custom_update_product_regular_price', 10, 2);
Where:
- Change the 99999 with your original form ID
- change 1111 with the actual regular price you want to set.

#2424925

Shane
Supporter

Languages: English (English )

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

Hello,

Thank you for getting in touch.

1. Where can I find the original Form ID?

A. The form ID can be seen when you go to Toolset -> User/Post Forms. There is an ID column that gives the ID for each form that was created.

2. Must the parameter be Run on the Font-End?

A. What Parameter are you referring to ?

3.Do I need the on-demand mode?
A. If it is an action Hook then is appropriate to select the on the demand mode because the function is called when it's time to be used.

4. Must I use the toolset_snippet_security_check line?
A. Yes as it prevents persons from directly accessing and running the file by using the file's URL path.

Thanks,
Shane

#2426499

Hi Shane,

Where to run the snippet: on the front-end? I use the snippet for the front end product submission form.

#2426629

Shane
Supporter

Languages: English (English )

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

Hello,

If the snippet is meant for the frontend only, then you can select this option.

Thanks,
Shane

#2428165

I added the code you provided but no price set.
The documentation says:
If the snippet is in the On demand mode, there must be a GET (or POST) parameter with the snippet slug, i.e. hidden link.
How and where do I put this.
Thx for answering!

Regards Loek

#2429615

Shane
Supporter

Languages: English (English )

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

Hi Loek,

What you will need to do is to set the code to "Run Always" and select "Frontend Only"as well as "AJAX Calls"

What Run on Demand does, is allow you to run the code only when you've placed the file path for the snippet in the URL. In your case you don't need this.

Thanks,
Shane

#2431047

Hi Shane,

I add the changes, but still it does not work.
Can you please help.

Thx!
Loek

#2431235

Shane
Supporter

Languages: English (English )

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

Hi Loek,

I'm assuming that the function below is the exact function that you have on your site.

function func_custom_update_product_regular_price($post_id, $form_data) {
// if a specific form
if ($form_data['id']==99999) {
update_post_meta($post_id,'_regular_price', 1111);
}
}
add_action('cred_save_data', 'func_custom_update_product_regular_price', 10, 2);

If so then you need to change the 9999 to the ID of the form that this function should apply to. Also ensure that you've clicked the Activate link on the snippet in order for it to be available.

Thanks,
Shane

#2433847
Screen Shot 08-08-22 at 09.11 PM.PNG

Hi Shane,

Still no result.
I got the following error:

#2433865

Shane
Supporter

Languages: English (English )

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

Hello,

Would you mind allowing me to have admin access to the website so that I can have a more detailed look at this one for you ?

I've enabled the private fields for your next response.

Thanks,
Shane

#2434365

Shane
Supporter

Languages: English (English )

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

Hello,

The should be working now.

The problem was that you had deleted the opening php tags for the code snippet.

The full code should be.

<?php
/**
 * New custom code snippet (replace this with snippet description).
 */

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.
function func_custom_update_product_regular_price($post_id, $form_data) {
// if a specific form
if ($form_data['id']==15) {
update_post_meta($post_id,'_regular_price', 50);
}
}
add_action('cred_save_data', 'func_custom_update_product_regular_price', 10, 2);

Please let me know if this helps.
Thanks,
Shane

#2434941

Hi Shane,

Code works but now other plugins do not work anymore.
Is there a possibility to use the regular price field in the form itself. Set default vale on it and locked this field for the user.

#2435233

Shane
Supporter

Languages: English (English )

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

Hello,

Can you clarify what you mean by other plugins don't work anymore ? Also can you specify which plugin ?

Set default vale on it and locked this field for the user.<?em>

Are you referring to locking the field on the frontend or backend ?

Please let me know.
Thanks,
Shane

#2435967

Hi Shane,

Thanks for your reply. The code you provided functions well, thanks for that.
The plugin I use which causes problems is Barn2 Product Table. This table is used as the product table.
It's situated on the shop page (Winkel pagina).
The problem is, after activation of the code you provided, that the price field (Prijs Profiel) is not visible anymore. The effect is that also the cart button (Toevoegen aan Winkelwagen) has disappeared.
Product fields and filters of the Barn2 plugin are correctly set.
The testcase I used for this is 999999 test, the product price was set to 50 by your code.
Can you please help what goes wrong?
Thx in advance for your support!

Regards,
Loek

#2436069

Shane
Supporter

Languages: English (English )

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

Hi Loek,

I'm not see how this function is causing a conflict as it should only run when a form is triggered.

Can you let me know a sample page where I can test the issue ?

Thanks,
Shane