Jump to content
Sign in to follow this  
Andrea D.

EXTRACT CUSTOM FIELDS FROM GetProducts local API

Recommended Posts

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)

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

$results['products']['product']['0']['customfields'][0][customfield][0][‘value’]
 

This is not flexible. It’s hard-pointed…Not a good practice 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Posted (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 by pRieStaKos

Share this post


Link to post
Share on other sites
Posted (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 by Andrea D.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated