I have a series of extra fields (prices) for my K2 items that I only want to show to logged in users. To add more, I need to show one field to one User Group (price A) and a different field to a different User Group (Price B). How, can I accomplish this?

I know I can do access level checks for modules, but since these are extra fields attached to K2 items, I'm fumbling for a way to accomplish this.

  • As a note, these extra fields are being used to show prices only to those with buyer accounts (user groups). I know there is a "K2Store" component, but I don't need carts, invoicing, stock, etc. All I need is the price displayed (which varies by user group). Feb 17, 2016 at 1:19

2 Answers 2


I was able to accomplish this using the following code (in abbreviated form):

<?php $user = JFactory::getUser(); ?>
<?php if(!$user->guest): ?>
<!-- Prices -->
<div class="moduletable">
<h3 class="specs">Pricing</h3>
  $none = true; 
  foreach ($this->item->extra_fields as $key=>$extraField) {
    if($extraField->value && $extraField->name=='Price A' && in_array(25,$user->groups)) {
      echo $extraField->value;
      $none = false;
    elseif($extraField->value && $extraField->name=='Price B' && in_array(26,$user->groups)) {
      echo $extraField->value;
      $none = false;
  if ($none) echo '<br/><p>Coming Soon!</p>';
<?php endif; ?>

Basically, I check to see if the user is logged in, then run through the extra fields to see if the field name is "Price A" and the user is in the user group "Price A" (ID=25). If it matches, I output the price and move on. If not, it does the same check for "Price B." If an extra field for price isn't assigned or the user doesn't have a price level, I give a encouraging message! ;)

  • Glad my answer pointed you in the right direction.
    – Terry Carter
    Feb 17, 2016 at 21:03
  • Yes, I was hoping I didn't actually have to override the component output. Instead, I was able to add this to my layout template. Feb 17, 2016 at 21:08
  • I have had to do the exact same thing in the past with some of my extensions, it works like a charm and saves a good bit of coding time.
    – Terry Carter
    Feb 17, 2016 at 21:09

Without installing K2 and fiddling with the code I can only give you my thoughts. You need to override the display for your custom fields view. Loop through each of the fields and use conditional statements to determine the visibility of the fields based on use access level or group.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.