Logman Posted December 9, 2017 Share Posted December 9, 2017 Is it possible to add a link to a config item option on an order form? We have a service with lots of config upgrades and would like to add links to info pages so clients can understand what the upgrade options are if they haven't seen them already. Thanks. Link to comment Share on other sites More sharing options...
brian! Posted December 9, 2017 Share Posted December 9, 2017 1 hour ago, Logman said: Is it possible to add a link to a config item option on an order form? not from the settings. whilst you could add the link code in the configurable option name, and then tweak the template to output it as a link, a button or whatever... the problem is that code within the config option name will then be visible in the remaining cart stages... now it's simple enough to remove, but you'd end up editing multiple templates (ordersummary, viewcart and probably the invoice templates too). i'd be tempted to just edit the configureproducts.tpl and add your code directly there... so if it were a one-off... {if $configoption.id eq '16'}<a href="http://www.google.com" class="btn btn-success btn-xs" role="button">More Info</a>{/if} if it's for multiple configurable options with different links, then you could use multiple if/else statements, or create an array of configurable option IDs and their relevant links - either in the template using Smarty, or using a ClientAreaPageCart hook... Link to comment Share on other sites More sharing options...
Logman Posted December 12, 2017 Author Share Posted December 12, 2017 Cheers Brian. Will be attempting this later this week. Link to comment Share on other sites More sharing options...
Logman Posted January 6, 2018 Author Share Posted January 6, 2018 I tried added the link html in the Option field but it just displayed code: I looked in the db and found the ID but I can't figure out where in configureproduct.tpl to place this code: {if $configoption.id eq '644'}<a href="http://www.google.com" class="btn btn-success btn-xs" role="button">More Info</a>{/if} Link to comment Share on other sites More sharing options...
sentq Posted January 6, 2018 Share Posted January 6, 2018 while Brian method could perfectly work, another option is to use ActionHooks for this task, simply create new PHP file inside /includes/hooks/ directory and place the following code inside it and it will do the job as intended to <?php /** * Allow links <a> in products configurable options name * @author SENTQ */ add_hook("ClientAreaPageCart", 1, function($vars){ foreach ($vars['configurableoptions'] as $index => $option){ $vars['configurableoptions'][$index]['optionname'] = html_entity_decode($option['optionname']); } return array("configurableoptions" => $vars['configurableoptions']); }); Link to comment Share on other sites More sharing options...
Logman Posted January 7, 2018 Author Share Posted January 7, 2018 It works but the HTML code shows on the order summary top right of the page: Link to comment Share on other sites More sharing options...
sentq Posted January 7, 2018 Share Posted January 7, 2018 (edited) this improvement will do the same in view cart page <?php /** * Allow links <a> in products configurable options name * @author SENTQ */ // Shopping Cart add_hook("ClientAreaPageCart", 1, function($vars){ // Cart -> View if ($vars['action'] === "view"){ foreach ($vars['products'] as $index => $product){ foreach ($product['configoptions'] as $optionid => $option){ $vars['products'][ $index ]['configoptions'][ $optionid ]['name'] = html_entity_decode($option['name']); } } return array("products" => $vars['products']); } // Cart -> Product Configuration if ($vars['action'] === "confproduct"){ foreach ($vars['configurableoptions'] as $index => $option){ $vars['configurableoptions'][ $index ]['optionname'] = html_entity_decode($option['optionname']); } return array("configurableoptions" => $vars['configurableoptions']); } }); // Client Area -> Product Details Page add_hook("ClientAreaPageProductDetails", 1, function($vars){ foreach ($vars['configurableoptions'] as $index => $option){ $vars['configurableoptions'][ $index ]['optionname'] = html_entity_decode($option['optionname']); } return array("configurableoptions" => $vars['configurableoptions']); }); // Admin Area -> Product Details Page add_hook("AdminAreaHeadOutput", 1, function($vars){ if ($vars['filename'] != "clientsservices"){ return; } return <<<EOF <script type="text/javascript"> $(document).ready(function(){ $(".fieldlabel").each(function(i, val){ var final = $('<textarea />').html($(this).text()).text(); $(this).html(final); }); }); </script> EOF; }); Edited January 9, 2018 by sentq improvements Link to comment Share on other sites More sharing options...
Logman Posted January 8, 2018 Author Share Posted January 8, 2018 Hi Sentq, I added this as "CartLinks.php" in /hooks but the cart summary on the order page still shows the HTML: Thanks for helping out. Really appreciate your time. Link to comment Share on other sites More sharing options...
sentq Posted January 8, 2018 Share Posted January 8, 2018 in this case we need to use @brian! method, open the following file for editing: /templates/orderforms/ordersummary.tpl replace this line (#12): <span class="pull-left"> » {$configoption.name}: {$configoption.optionname}</span> with this one: <span class="pull-left"> » {$configoption.name|unescape}: {$configoption.optionname}</span> Link to comment Share on other sites More sharing options...
Logman Posted January 8, 2018 Author Share Posted January 8, 2018 That's a bit better but is there any way to strip the HTML from the order summary completely? Looks a bit strange. Link to comment Share on other sites More sharing options...
sentq Posted January 8, 2018 Share Posted January 8, 2018 use strip_tags instead of unescape Link to comment Share on other sites More sharing options...
Logman Posted January 8, 2018 Author Share Posted January 8, 2018 Thanks, almost there. How do I also strip out the HTML from the order emails that get sent - one to admin, and also the confirmation that gets sent to the client? I guess I'll also need to do this in the invoices too. Link to comment Share on other sites More sharing options...
Logman Posted January 8, 2018 Author Share Posted January 8, 2018 I also figured out where to add unescape in the viewinvoice and clientareaproductdetails templates. Just need to work out the emails and also if possible the WHMCS admin client Products/Services page. I looked in the blend templates and see no mention of it. Can that be edited? Link to comment Share on other sites More sharing options...
sentq Posted January 9, 2018 Share Posted January 9, 2018 I've edited to ActionHook code to make it work in product details page in both client and admin areas for emails you'll need to use the "unescape" modifier as we did with templates before, but you will need to enable the function in the security policy https://docs.whmcs.com/Smarty_Security_Policy Link to comment Share on other sites More sharing options...
Logman Posted January 9, 2018 Author Share Posted January 9, 2018 The Hook works perfect, thanks. Added the Smarty security policy for unescape, found I could simply add |unescape to $order_details, $order_items, $data_option etc. Turned out to be a bit more involved than I though but worth it I think for upsells. Will the default Email Templates get written over on upgrades? Thanks so much for your help! Link to comment Share on other sites More sharing options...
sentq Posted January 9, 2018 Share Posted January 9, 2018 1 hour ago, Logman said: Will the default Email Templates get written over on upgrades? not common but possible Link to comment Share on other sites More sharing options...
brian! Posted January 13, 2018 Share Posted January 13, 2018 FWIW, and this is probably too late for @Logman as he's likely too far down the road of removing from additional pages, but i'd be tempted to tweak @sentq hook code and instead of having the description/link in the option name, remove it from there and create a Language Override for that configurable option description and/or link.. there would be a number of advantages to this method... you can create your descriptions in multiple languages and the client will see the description in their chosen language (not necessarily English). the language overrides can contain HTML and/or css styling... including links specific to that language - e.g., French visitors might see one link, German users might see another. as you are now adding to the output only on specific pages, you no longer need to remove additional code from other templates such as ordersummary, invoices, emails etc. if a configurable option doesn't contain a language override description, then the hook will not attempt to add any code. <?php /** * Allow links <a> in products configurable options name * @author SENTQ */ // Shopping Cart add_hook("ClientAreaPageCart", 1, function($vars){ GLOBAL $_LANG; // Cart -> Product Configuration if ($vars['action'] === "confproduct"){ foreach ($vars['configurableoptions'] as $index => $option){ if (!empty($_LANG["configoptiondesc".$option['id']])) { $vars['configurableoptions'][ $index ]['optionname'] = $option['optionname'].'<br>'.Lang::trans("configoptiondesc".$option['id']); } } return array("configurableoptions" => $vars['configurableoptions']); } }); in the above example, i've only modified them on the product configuration page... <?php $_LANG['configoptiondesc36'] = "<small>Adds our company name to your servername for a small discount. <a href=\"http://www.google.com\" data-toggle=\"tooltip\" title=\"Link To Google\">Special Link</a></small>"; if you wanted to use the same descriptions/links for all languages, you could either copy&paste the override strings into the other language overrides - or probably easier, create an array of descriptions/links in the hook and bypass using Language Overrides entirely. Link to comment Share on other sites More sharing options...
Logman Posted February 14, 2018 Author Share Posted February 14, 2018 Thanks Brian. I might go this route in future. @sentq this works fine. However, if you add a product for a client in the admin area (ordersadd.php) the raw html is shown. It doesn't really matter because the client never sees it. But if it can be pretty'd up in the hook, why not? When viewing a product in the admin area the links work fine. Link to comment Share on other sites More sharing options...
Recommended Posts