Inna Posted December 30, 2020 Share Posted December 30, 2020 Hello, I added a new custom client field for phone number (I use 3rd party addon which requires new custom field), and my problem is I cannot add that field into the registration page and client area page. I googled a lot regarding how to do that, but none of them unfortunately worked. I use WHMCS v8 with custom theme, but it neither worked with default theme. When I refer to ` tblcustomfields` table, I see this field has `relid` equals with 0 and `id` is 32, and now when I see `tblcustomfieldsvalues`, that phone number of the test client has `fieldid` equals to 32 and `relid` is 1 which is I think client number and it's correct if my assumption is right. The I tried and failed is that the new code I add to template is not shown at all. I should mention that I added {debug} to that template and this works and shows debug info, but when I want to show that field in these two pages, I'm unable to do that. Would you please help me how may I reach it? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 30, 2020 Share Posted December 30, 2020 1 hour ago, Inna said: Would you please help me how may I reach it? have you ensured that the custom field has its "Show On Order Form" checkbox ticked ? https://docs.whmcs.com/Custom_Fields#Client_Custom_Fields Quote You can create client profile-related fields in Configuration () > System Settings > Custom Client Fields. Set these to Show on Order Form if you want the client to enter them. You can also leave them as only visible in the admin area, for private entries. The client can view and edit the field values from the client area unless you set them to admin only. 1 Quote Link to comment Share on other sites More sharing options...
Inna Posted December 30, 2020 Author Share Posted December 30, 2020 Hello, Regarding Show On Order Form, I thought it will show on Order Form, not Registration page:) This is now fixed:) But I'm still unable to show the field on client area page. My field page is not English, it's for example 'تلفن همراه' which means phone number. So as per the docs, I should write {$service_custom_field_تلفنهمراه} to show in the pages, am I right? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 30, 2020 Share Posted December 30, 2020 35 minutes ago, Inna said: So as per the docs, I should write {$service_custom_field_تلفنهمراه} to show in the pages, am I right? that should only apply to the email templates (products), not the client area. if you purely wanted to show the value of the customfield, then it would be available to the $clientsdetails array when a user is logged in so in the above example, {$clientsdetails.customfields21} would show the value... its position in that array will be defined by its "Display Order" value - though it's relative position can change if you add other client fields. if you needed to use a hook to query the database for it's value, then you could use... <?php # Client Custom Field Hook # Written by brian! use WHMCS\Database\Capsule; function client_custom_field_phone_hook($vars) { $client = Menu::context('client'); $fieldid = 92; if (!is_null($client)) { $cfvalue = Capsule::table('tblcustomfieldsvalues')->where([['fieldid',$fieldid],['relid',$client->id]])->value('value'); return array("customfieldphone" => $cfvalue); } } add_hook("ClientAreaPage", 1, "client_custom_field_phone_hook"); and that would allow you to use {$customdieldphone} in your template to display it's value - the only line that you should need to change is its fieldid value and that will be the ID value of this customfield in tblcustomfields - in the above example, I can see its value is 92 from the {debug} screenshot, but you could equally find the value from looking in tblcustomfields if you're familiar with that now. also, it's worth mentioning that the above hook would run on every client page - if you only need it to run on a specific page, then you would either have to limit the hook to check the template and only run on that specific page (that's a simple if statement), of you may be able to use a more specific hook point rather than ClientAreaPage (but that will depend on which template you're trying to output this text). 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.