Support » Plugins » Hacks » Suppress view of label if user logged out

  • Hi, I am going crazy with this problem so I hope somebody can help.

    http://wattev2buy.com/product/best-ev-in-china/

    There are three meta fields in woo commerce that I don’t want to show to logged out users. The source of the metadata, however, is from WP Front End Pro and they advised the following

    http://docs.wedevs.com/docs/wp-user-frontend-pro/tutorials/showing-meta-fields-in-frontend/

    My poor effort is:

    <div class=”<?php if ( is_user_logged_in() ) echo “logged-in”; else echo “not-logged-in”; ?>”>
    <?php echo get_post_meta( $post->ID, ‘_email’, true ); ?>
    <?php echo get_post_meta( $post->ID, ‘_regular_price’, true ); ?>

    And then in style css

    .not-logged-in .get_post_meta( $post->ID, _email ) {
    display: none;
    }
    .not-logged-in .get_post_meta( $post->ID,_regular_price ) {
    display: none;
    }

    And then there is a field I don’t want to show to logged in or out users – the _gallery_images at bottom.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi, @wynandoosen. For the CSS, the rule should look like this:

    .not-logged-in {
    display: none;
    }

    (The get_post_meta part is all PHP, so you can’t use it in your CSS.)

    But you’d really be better off keeping these values from outputting to the page in the first place (instead of trying to hide them after the fact), e.g.:

    <?php if ( is_user_logged_in() ) {
    	echo get_post_meta( $post->ID, '_email', true );
    	echo get_post_meta( $post->ID, '_regular_price', true );
    } ?>
    Thread Starter wynandoosen

    (@wynandoosen)

    Thanks for the response. Still can’t get it to work, the big question at the moment I think is in which file I should put the php, is it DIVI single page, or WOOCOMMERCE single product. It did not work in the Snippets plug-in I use.

    If you are customising theme files then you should be using a child theme, details here:
    creating a child theme http://codex.wordpress.org/Child_Themes
    If you don’t use a child theme, then your changes will be lost in a theme update.

    When trying to figure which page template is being used, I put an echo of the text of the template name into the file, I comment it out later.
    If it turns out you do not need a specific template customised, be sure to delete it from the child theme. Only customise what you need, only keep what you have customised, the parent theme will look after the rest.

    It seems that there are plugins in use here that also provide layouts that can be customised. If dong this you need to take care that you can recover your changes if there is a plugin update.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Suppress view of label if user logged out’ is closed to new replies.