[Resolved] How to add generic fields data to notification body
This support ticket is created 8 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.
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.
Generic fields are not handled and processed automatically by the CRED. But CRED provides a sophisticated way to deal with such fields on the fly. I suggest using following example code:
Please add this code to your theme's functions.php file.
This code actually does followings:
- Adds 'cred_body_notification_codes' filter to the filters queue. This filter is defined by CRED to render default placeholders.
- It takes a parameter and passes the array of existing placeholders (defined by CRED).
- All we need to add our own %%Problema%% placeholder and render it accordingly. This what it does within the callback function 'cb_problema_placeholder'.
- During this addition, it grabs the generic field's value from standard $_REQUEST super global array.
You can do the same with Subject Field also. Remember to use 'cred_subject_notification_codes' filter, just like above. I hope it resolves the issue.
The fields from a Post Type and User Profile (standard and custom) should work fine with their respective methods (i.e. types short code or other short codes provided). However, for Generic Fields the code I provided above should work just fine - regardless of CRED Forms and User Forms.
All you need to make sure that you add new placeholders in the code. So you can replace their values accordingly.
If you can copy your code here, I can see for a problem.
This is really weird that your code isn't working, although it looks just fine. However, can you please try replacing your add_filter line with following:
Notice 99 in the 3rd parameter of add_filter. This is a priority attribute. Setting it to higher level will ensure that it runs lately. I suspect running it too early may not be working in this case. Please try the above line.
If it still does not work for you. Please provide temporary access to your site. So I can look for more details.
I have enabled your next reply as private, please input all details in that area. Please mention the links to the pages, views, forms, CPTs and configurations in question.
Please take a backup of your site, before proceeding. Also make sure the functions.php is writeable so I can make necessary changes (if needed).
Thank you for providing the access information. I was able to look into your website and have corrected the issue with %%pasto-kodas4%%. While %%problema%% is already working fine.
However, please consider followings, on order to get other [types] short codes and other %% placeholders to work:
1) For [types usermeta] short codes, please update CRED and Layout plugins as well. I noticed that you are using a previous release than the current one. Updating to CRED 1.4.2.1 and Layouts 1.4.2 should fix this issue.
2) For %%pasto-kodas3%% you need to activate the appropriate filter, but remember to add a relevant field in the form as well. Since I don't see a field representing this placeholder. But the method is the same as for other working placeholders.
3) Remember, when you are referencing a form field (not generic field), you should grab it by adding 'wpcf-' as a prefix to it's name. For example your field 'pasto-kodas' should be grabbed as $_REQUEST['wpcf-pasto-kodas'] in the filter. I have corrected this in your functions.php file. However, generic fields do not have such a prefix in their names and should be referenced as-it-is (i.e. problema).
Apparently, if you upgrade CRED and Layouts to the latest versions, rest of the issues should also be solved. Please let me know if issue is resolved after the update. Please see https://toolset.com/account/downloads/ for latest available versions of Toolset Plugins.