skip to Main Content

I have a membership site and need prices hidden until the user is logged in. How can I adjust this so prices are hidden only for users who are NOT logged in?

.imagemapper-wrapper .my_product_price { display:none !important; }

Currently prices are hidden from everyone.

4

Answers


  1. Chosen as BEST ANSWER

    So I ended up merging two answers together. display: inherit wasn't working so I tried block !important instead and it worked like a charm. Thank you all for your advice and suggestions. I am now able to hide both the price and add to cart buttons when a user is NOT logged and show them when they are! I was beyond excited when I finally got this to work. Thank you all!

    #mega_main_menu>.menu_holder>.menu_inner>ul>li.default_dropdown .mega_dropdown>li>.item_link {height:auto}
    
    .logged-in .imagemapper-wrapper .my_product_price {
          display: block !important;
        }
    
    .imagemapper-wrapper .my_product_price { display:none !important; }
    
    .logged-in .imagemapper-wrapper .my_add_item { display:block !important; }
    
    .imagemapper-wrapper .my_add_item { display:none !important; }
    
    .logged-in .my_product_footer .my_view_item {width: 50%}
    
    .my_product_footer .my_view_item {width: 100%}
    

  2. One way you can do this is with the wp_head hook. In the hook you can echo the style if a user is logged in with is_user_logged_in(). See below:

    <?php
    
    // functions.php
    
    add_action('wp_head', function(){
        if (is_user_logged_in()) {
            echo '<style>.imagemapper-wrapper .my_product_price { display:none !important; }</style>';
        }
    });
    

    Another option is to use a custom css classname:

    // functions.php
    add_filter('body_class', function($classlist) {
        // add custom css class to body element if user is logged in
        if (is_user_logged_in()) {
            $classlist[] = 'user-is-loggedin';
        }
    
        return $classlist;
    });
    

    Then is your css use the new classname:

    // your-stylesheet.css
    .imagemapper-wrapper .my_product_price { display:none; }
    .user-is-loggedin .imagemapper-wrapper .my_product_price { display:block !important; }
    
    Login or Signup to reply.
  3. If you want to use CSS instead of removing the pricing unless the user is logged in, use the wp_head filter. Put this in your functions.php file:

      add_action('wp_head', static function() {
            if ( ! is_user_logged_in() ) {
             echo "<style>.imagemapper-wrapper .my_product_price { display:none !important;}</style>";
            }
       }
    

    This uses is_user_logged_in() function to test if the user is logged in. If the user is not logged in, print this style in your header.

    Login or Signup to reply.
  4. CSS only option:

        .imagemapper-wrapper .my_product_price {
          display: none;
        }
    
        .logged-in .imagemapper-wrapper .my_product_price {
          display: inherit;
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search