i’ve found the following code to make an element change to display:block; if a user is logged in
.logged-in .price{
display: none;
}
and also
<?php if ( is_user_logged_in() ) {
echo '<style>p.price {display:none;}</style>';
} else {
echo '<style>p.price {display:block;}</style>';
}
?>
but neither seems to work properly. it will hide the element, but if i log out, the element is still hidden. does anyone have an answer? thankyou 🙂
3
Answers
Thanks for this. The addition I forgot to mention was to have the element to stay hidden until clicked again - which is a localStorage thing.
Final code is below:
The body tag will have a
logged-in
class when the user is logged in. So using the following will work.If you want to remove the
!important
attribute then you would need to target more specifically which.price
element you wish to remove due to Woocommerce being very specific with it’s css selectors.Also to note, you can add a
:not()
modified to the body selector if you wish to do the reverse, i.e…Try following code that worked fine for me.