VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: saviB on October 03, 2017, 15:05:08 PM

Title: Hide Custom Fields By Login Status
Post by: saviB on October 03, 2017, 15:05:08 PM
VirtueMart 3.2.4
Joomla! 3.8.0

HI All. I've been searching for several hours now with no luck. I need to show / hide custom fields (string / cart attribute) by login status. Any help is appreciated.

What I have now: Product prices are hidden for non logged in viewers using shopper groups. BUT - custom field options with price modifiers are not tied to this condition. This leaves the public seeing a product with no price or way to add to cart - but they can see a drop list of conditions (in my case, sizes) with price additions. So while they can't see the beginning price, they can see that size "A" adds $10 and size "B" adds $20 etc. I need to hide these custom field variants to anyone not logged in.

I thought Custom Field Custom Group was the way to go - but I only see the option to hide for everyone or to show only for admin - same options found in each Custom Field.
Title: Re: Hide Custom Fields By Login Status
Post by: GJC Web Design on October 03, 2017, 23:51:37 PM
Just hide them with css

trigger in the normal way by detecting the j user

$user = JFactory::getUser();

        if ($user->get('guest') == 1) {
              echo  'write your css here';

}
Title: Re: Hide Custom Fields By Login Status
Post by: saviB on October 04, 2017, 12:23:36 PM
Exactly what I was looking for, thanks. I'm no programmer. In what file would I put the jquerry block?
Title: Re: Hide Custom Fields By Login Status
Post by: saviB on October 04, 2017, 13:22:11 PM
I've posted this in teh template forum too - if i get an answer I'll add it here:

Objective: Hide custom fields in Virtuemart3 product detail pages using PHP/jQuery.

I need to add some JS to my Myriad template to hide Virtuemart custom fields by log in status. I've gotten this far:

$user = JFactory::getUser();

if ($user->get('guest') == 1) {
$('.vm-customfields-wrap').css("display","none");

}

And now I'm stuck. I believe the syntax of the CSS may be incorrect. I've seen it used differently in different places. For instance, $('.vm-customfields-wrap').css('display:none');

So, 1. would someone please let me know which is correct and if neither - educate me to the proper syntax?
2. In what file would I place the code block? I assume in the template js folder - but I see no tmpl or easy way to add custom JS as there is in Gantry 5.
3. Does it need any wrapper, like <?php ?>

MUCH appreciated!
Title: Re: Hide Custom Fields By Login Status
Post by: kishoreonwork on October 04, 2017, 18:39:02 PM
try this code




$user = JFactory::getUser();

if ($user->get('guest') == 1) {

echo '<style type="text/css">.vm-customfields-wrap{display:none;}</style>';
}
Title: Re: Hide Custom Fields By Login Status
Post by: GJC Web Design on October 04, 2017, 20:47:39 PM
@kis will work

you were mixing php and JS jquery!
Title: Re: Hide Custom Fields By Login Status
Post by: saviB on October 05, 2017, 14:58:18 PM
Thanks @kis and GJC. The code works!

I added it to components/com_virtuemart/views/productdetails/view.html.php. Right at the bottom before "// pure php no closing tag"

If there is a better place to use it - all suggestions are welcome. Is there a way to add a custom file that won't get overwritten with updates?

It may be a smart addition to VM to be able to hide all custom fields that effect price. Just hiding the price from the string would be perfect, but there is no class assigned to .vm-chzn-select options - so css won't do it..

I think it would make sense for that to be tied to the existing price per user group. Example:

Tshirts are $24. You have to be registered and log in to see prices.

Size options are available (custom field cart attributes) but they effect price, so they show a currency amount with each option.

SIZE OPTIONS
S= +$1
M= +$2
etc.

With the fix you folks provide (thank you again) The entire option set is hidden for public. It would be good if the public could see the options - just not  the price modifiers. So public would see:

SIZE OPTIONS
S
M
etc.


Thanks again!