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.
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.
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.
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.
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!
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.
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.
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);
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.
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!