Andrea D. Posted July 30, 2022 Share Posted July 30, 2022 Hello, I am doing $command = "GetProducts"; $values = array( 'pid' => '1', ); $results = localAPI($command, $values); print_r($results['products']['product']['0']['customfield']); logActivity("hook has run. Posted Vars: " . print_r($results['products']['product']['0']['customfield'], true)); It should give in logs the value of the customfield but it is not giving it (after the ":" nothing is being displayed) 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted July 30, 2022 Share Posted July 30, 2022 (edited) $results['products']['product']['0']['customfields'] https://developers.whmcs.com/api-reference/getproducts/ Edited July 30, 2022 by pRieStaKos 0 Quote Link to comment Share on other sites More sharing options...
Andrea D. Posted July 30, 2022 Author Share Posted July 30, 2022 9 minutes ago, pRieStaKos said: $results['products']['product']['0']['customfields'] https://developers.whmcs.com/api-reference/getproducts/ Thank you! it worked but I am getting hook has run. Posted Vars: Array ( [customfield] => Array ( [0] => Array ( [id] => 6 [name] => WhitelistedIP [translated_name] => WhitelistedIP [value] => 8.8.8.8 ) [1] => Array ( [id] => 4 [name] => Additional White Listed IPs [translated_name] not the value of the WhitelistedIP option. How can I do that? Thank you in advance! 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted July 30, 2022 Share Posted July 30, 2022 $results['products']['product']['0']['customfields'][0][customfield][0][‘value’] This is not flexible. It’s hard-pointed…Not a good practice 0 Quote Link to comment Share on other sites More sharing options...
Andrea D. Posted July 30, 2022 Author Share Posted July 30, 2022 12 minutes ago, pRieStaKos said: $results['products']['product']['0']['customfields'][0][customfield][0][‘value’] This is not flexible. It’s hard-pointed…Not a good practice Now it is not outputting nothing….What do you mean by “is not flexible”? I know exclusion the position and the name of the custom field. 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted July 30, 2022 Share Posted July 30, 2022 (edited) $results['products']['product'][0]['customfields'][‘customfield’][0][‘value’] I mean this will return you the records of the first product. Not every product. You need a forearch loop. Edited July 30, 2022 by pRieStaKos 0 Quote Link to comment Share on other sites More sharing options...
Andrea D. Posted July 31, 2022 Author Share Posted July 31, 2022 (edited) 14 hours ago, pRieStaKos said: $results['products']['product'][0]['customfields'][‘customfield’][0][‘value’] I mean this will return you the records of the first product. Not every product. You need a forearch loop. Hello, basically what I am doing is: - customer pays - order activated automatically (whmcs settings) - create module occurs - hooks called: - the hooks should collect the custom field and store it in a variable. What is the best way to do it. What would you reccomend. Should i use configurable options instead? Edit: btw if the first product is the last ordered product the hook should work. Can you confirm it? Thank you! Edited July 31, 2022 by Andrea D. 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted July 31, 2022 Share Posted July 31, 2022 4 minutes ago, Andrea D. said: Hello, basically what I am doing is: - customer pays - order activated automatically (whmcs settings) - create module occurs - hooks called: - the hooks should collect the custom field and store it in a variable. What is the best way to do it. What would you reccomend. Should i use configurable options instead? Thank you! Check AfterModuleCreate to get the customfield of the service. It’s better. https://developers.whmcs.com/hooks-reference/module/#aftermodulecreate 0 Quote Link to comment Share on other sites More sharing options...
Andrea D. Posted July 31, 2022 Author Share Posted July 31, 2022 5 hours ago, pRieStaKos said: Check AfterModuleCreate to get the customfield of the service. It’s better. https://developers.whmcs.com/hooks-reference/module/#aftermodulecreate I am using AfterModuleCreate hook now. The question is if the first product is the last ordered product the hook should work. Can you confirm it? But how can i extract the exact value from the custom field? 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted July 31, 2022 Share Posted July 31, 2022 1 minute ago, Andrea D. said: I am using AfterModuleCreate hook now. The question is if the first product is the last ordered product the hook should work. Can you confirm it? But how can i extract the exact value from the custom field? You will get the serviceid from parameters through $vars. It will be the service you create before. Add a check of pid to verify that the hook will check the product you want. And then get the customfield value. 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.