News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Hide Custom Fields By Login Status

Started by saviB, October 03, 2017, 15:05:08 PM

Previous topic - Next topic

saviB

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.

GJC Web Design

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';

}
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

saviB

Exactly what I was looking for, thanks. I'm no programmer. In what file would I put the jquerry block?

saviB

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!

kishoreonwork

try this code




$user = JFactory::getUser();

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

echo '<style type="text/css">.vm-customfields-wrap{display:none;}</style>';
}
I am available for paid joomla and virtuemart consulting.
http://www.kishoreweblabs.com/
skype kishore2607

GJC Web Design

@kis will work

you were mixing php and JS jquery!
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

saviB

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!