nicktcy Posted January 2, 2019 Share Posted January 2, 2019 Hi, I am looking for a hook or product that could hide certain products from public visitor. Any idea? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 3, 2019 Share Posted January 3, 2019 On 02/01/2019 at 09:55, nicktcy said: I am looking for a hook or product that could hide certain products from public visitor. Any idea? you could try the following hook to remove specific products from the cart products pages for non-clients... <?php /** * Hide Products Based On Loggedin Status * @author brian! */ function cart_hide_product_hook($vars) { $client = Menu::context('client'); if ($vars['templatefile']=='products'){ $products = $vars['products']; $removed = [45]; if (!$client) { foreach ($products as $k => $item) { if (in_array($item['pid'],$removed)) { unset($products[$k]); } } return array("products" => $products); } } } add_hook("ClientAreaPageCart", 1, "cart_hide_product_hook"); the only line that you should need to change is... $removed = [45]; which contains the list of Product IDs that you want to hide to non-clients... though bare in mind that they could still access the product via a direct url link if they know the pid - I daresay that the hook could be expanded to prevent that possibility if you thought it was essential to do so, but I wouldn't have thought it necessary. 0 Quote Link to comment Share on other sites More sharing options...
roxthaworld1 Posted March 8, 2020 Share Posted March 8, 2020 On 1/4/2019 at 12:55 AM, brian! said: you could try the following hook to remove specific products from the cart products pages for non-clients... <?php /** * Hide Products Based On Loggedin Status * @author brian! */ function cart_hide_product_hook($vars) { $client = Menu::context('client'); if ($vars['templatefile']=='products'){ $products = $vars['products']; $removed = [45]; if (!$client) { foreach ($products as $k => $item) { if (in_array($item['pid'],$removed)) { unset($products[$k]); } } return array("products" => $products); } } } add_hook("ClientAreaPageCart", 1, "cart_hide_product_hook"); the only line that you should need to change is... $removed = [45]; which contains the list of Product IDs that you want to hide to non-clients... though bare in mind that they could still access the product via a direct url link if they know the pid - I daresay that the hook could be expanded to prevent that possibility if you thought it was essential to do so, but I wouldn't have thought it necessary. thanks, Just used this and very helpful is there a way to expand it to have a message on the product page after youve hidden it all at the moment its just blank 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 8, 2020 Share Posted March 8, 2020 10 hours ago, roxthaworld1 said: is there a way to expand it to have a message on the product page after you've hidden it all at the moment its just blank <?php /** * Hide Products Based On Loggedin Status * @author brian! */ function cart_hide_product_hook($vars) { $client = Menu::context('client'); if ($vars['templatefile']=='products'){ $products = $vars['products']; $removed = [45]; if (!$client) { foreach ($products as $k => $item) { if (in_array($item['pid'],$removed)) { unset($products[$k]); } } if (empty($products)) { $errormessage = Lang::trans('orderForm.errorNoProducts'); } return array("products" => $products, "errormessage" => $errormessage); } } } add_hook("ClientAreaPageCart", 1, "cart_hide_product_hook"); 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.