Jump to content

Let a hook work for all pages on WHMCS


robinhood791

Recommended Posts

Hello,

I'm currently working on our new web design for our WHMCS,and made a hook that gets some information about our product groups. That is the name and the product tagline. This hook only works on the home page but needs to work on all of the pages. This might be really stupid, but I really didn't see the solution. 

The hook:

<?php

use Illuminate\Database\Capsule\Manager as Capsule;

function hook_getProductGroups($vars){

   # Get Product Groups
           $getProductGroups = Capsule::table('tblproductgroups')
                               ->where('tblproductgroups.hidden', '0')
                               ->select('id', 'name', 'tagline')
                               ->orderBy('order', 'asc')
                               ->get();

   $encodedata = json_encode($getProductGroups);
   $decodedata = json_decode($encodedata, true);

   return array("productgroups" => $decodedata);
}
add_hook("ClientAreaPageHome", 1, "hook_getProductGroups");


The code:

                    {foreach $productgroups as $pgroup}
                        <a href="cart.php?gid={$pgroup.id}">{$pgroup.name}
                            {if $pgroup.tagline}
                                <br>
                                <p>{$pgroup.tagline} <i style="margin-left: 1rem;" class="fas fa-arrow-right"></i></p>
                            {/if}
                        </a>
                    {/foreach}



I think it has something to do with the add_hook thing, but I haven't found it yet. Hope someone can help me here.
 

Link to comment
Share on other sites

13 hours ago, robinhood791 said:

I'm currently working on our new web design for our WHMCS,and made a hook that gets some information about our product groups.

I recognise that hook! 🙂

13 hours ago, robinhood791 said:

This might be really stupid, but I really didn't see the solution. 

you would just need to change ClientAreaPageHome to ClientAreaPage - if you do that, the hook will run on (virtually) every client area page. thanks.png

generally, I tend to suggest only running hooks on the pages where they're needed (to avoid unnecessary resource usage) - but if it's only one hook, it shouldn't make much difference.

Link to comment
Share on other sites

15 hours ago, robinhood791 said:

But how do you pull and show the item name(s), price('s), and quantity(s) in that modal (that has to be accessed across all pages)?

with a lot of work... 😓

15 hours ago, robinhood791 said:

It the shopping cart stored in a $_SESSION and if so, how do you echo that? 

the contents of the basket are available in the session (in a limited way) - but from memory, I don't think it will include product names  (only their IDs) or prices..

if you're doing this in the template, then you can access the cart session array using {$smarty.session.cart|print_r) - the print_r just expands the array so you can see what's inside it...

it might also be helpful to take a look at the cartnumitems.php data feed code in the feeds directory as that accesses the session and can be used on any page when you want to show the number of items in the cart... that should help you too with access the session in php.

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