Display product code to only registered users

  • Posts: 1147
  • Thank you received: 13
  • Hikashop Business
4 days 12 hours ago #371361

-- HikaShop version -- : 6.4.0
-- Joomla version -- : 5.4.3
-- PHP version -- : 8.3

Hi!

I'm building a B2B eshop, so i need to hide the product code from public group and display it to only registered users.
How can i do that?

Thank you!

Please Log in or Create an account to join the conversation.

  • Posts: 85393
  • Thank you received: 13962
  • MODERATOR
4 days 8 hours ago #371364

Hi,

The simplest approach would be to turn off the "Show product code" setting in Display > Configuration > Product page, so that the product code is hidden everywhere by default (product page, cart, emails, invoices, etc.).

Then, create a view override to display it only for logged-in users where you want it. Go to Display > Views, find the file `show_default.php` in the product view (or whichever layout you use), and click "Edit" to create an override.

In the override, add the following code where you want the product code to appear:

<?php if(!JFactory::getUser()->guest && !empty($this->element->product_code)) { ?>
    <span class="hikashop_product_code_main"><?php echo $this->element->product_code; ?></span>
<?php } ?>

You can do the same in the listing layout (e.g. `listing_img_title.php`) if you also want to show the code on category pages for registered users but you need to change $this->element to $this->row

Last edit: 4 days 6 hours ago by nicolas.
The following user(s) said Thank You: verzevoul

Please Log in or Create an account to join the conversation.

  • Posts: 1147
  • Thank you received: 13
  • Hikashop Business
4 days 8 hours ago #371366

Great thank you!

What about product's listing page?
I added the code in the view file listing_img_title.php but didn't work.

Please Log in or Create an account to join the conversation.

  • Posts: 85393
  • Thank you received: 13962
  • MODERATOR
4 days 5 hours ago #371368

Right. I've updated my message for the listing.

The following user(s) said Thank You: verzevoul

Please Log in or Create an account to join the conversation.

Time to create page: 0.057 seconds
Powered by Kunena Forum