Jump to content

Create a (hyper)link in Product Custom Field


DV8

Recommended Posts

Hi,

 

Rather than posting the whole link, which when clicked on let's you download a playlist, I would rather just put the word Download.

I'm adding extra (and unique) information to a product for each client using Custom Field in Products/Services. I've set it as a URL and go to the client's profile and enter the URL. But rather than the whole string appearing in the additional information area in client area, I want to put a word or phrase. I thought I could just use html in the field - <a href="http://www.google.com">text here</a>

 

I'm using version 7.10.2 which I think is the most recent I can use on my server according to the hosting service. I've attached a screenshot. Between the two red marks I'd like that link to be just a word or phrase.

 

Thanks

DV

Screenshot (91)_LI.jpg

Link to comment
Share on other sites

On 10/08/2020 at 20:25, DV8 said:

I thought I could just use html in the field - <a href="http://www.google.com">text here</a>

I suspect you'd have to code WHMCS to do what you want - which either means editing the clientareaproductdetails.tpl template and changing....

{$field.value}

to...

{if $field.type eq 'link'}<a href="{$field.rawvalue}" target="_blank">{$field.description}</a>{else}{$field.value}{/if}

and i'm assuming with this that you've added "Download" as the description field of the product custom field... if you haven''t, and these are the only links you're going to use, then you could hardocde Download in the output, but it would be better to pull the value from the description field.

the other way would be a hook that loops thought the product custom field array, if a field is a link, then replaces the values much as per above.

Link to comment
Share on other sites

Hey Brian,

Thanks for replying. Your replies to others have been most helpful but the time came to post my own query. Also, I need to start getting those 10 posts out of the way to get help quicker!!!

So, in your reply you've given me the code to edit the mentioned .tpl template. For the second option, what would the hook look like? I'm just learning hooks and have some added already.  If a hook can solve it, then I like to give it a go first.

 

Thanks

DV

 

 

Link to comment
Share on other sites

13 hours ago, DV8 said:

Your replies to others have been most helpful but the time came to post my own query.

that time comes to us all at some point. 🙂

13 hours ago, DV8 said:

Also, I need to start getting those 10 posts out of the way to get help quicker!!!

i'm often PM'd by new users as it can be quicker than waiting days for their post to be brought out of moderation...

13 hours ago, DV8 said:

So, in your reply you've given me the code to edit the mentioned .tpl template.

that was quicker for me to post yesterday - I was being lazy as I was melting in the current heatwave! 🌞

13 hours ago, DV8 said:

For the second option, what would the hook look like? I'm just learning hooks and have some added already.  If a hook can solve it, then I like to give it a go first.

it would be along the lines of...

<?php

# Product Details Custom Link Hook
# Written by brian!

function product_details__custom_field_links_hook($vars) {
	
	$customfields = $vars['customfields'];
	foreach ($customfields as $key => $field) {
		if ($field['type'] == "link") {
			//$customfields[$key]['value'] = '<a href="'.$field['rawvalue'].'" target="_blank">'.Lang::trans('downloadname').'</a>';
			$customfields[$key]['value'] = '<a href="'.$field['rawvalue'].'" target="_blank">'.$field['description'].'</a>';
		}
	}
	return array("customfields" => $customfields);
}
add_hook("ClientAreaPageProductDetails", 1, "product_details__custom_field_links_hook");

there are two things to note with this hook...

  1. you only need one of the $customfields[$key] lines to be included...
    * the first (in red and commented out) would use the translation of the word "Download" in the client's current language - if you want to use that, just remove the two slashes and the alternative line below it.
    * the second (currently active in green) reproduces what the Smarty template code did previously and uses the description field from the product custom field setup.
  2. the above code is currently using the ClientAreaPageProductDetails hook point - that means that it will run for products that don't have a module assigned to them that use alternative templates, e.g the most obvious example being cPanel - in other words, the above hook, as written, won't work with cPanel products (though from that screenshot, I assume it's not a cPanel product that demo product is using).
    if you needed the hook to work on cPanel products too, then you can simply change the hook point to ClientAreaProductDetailsPreModuleTemplate and that should work on both cPanel and non-cPanel products (at least works with cPanel/Autorelease products - untested with Plesk or others).
Link to comment
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.

  • 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