• Hi, i added some fields in the single product page by this plugin and im wondering how can i to restrict this new information for the visitors. I saw there are many ways but it doesnt work because i dont knwo where i need to add that. Can you help me?

    I add the link of the example page. I need to hide the “zona de trabajo” and the short description, so the visitors could see “this content is restrict, you need to register to see that”…

    Thank you!

    • This topic was modified 4 years, 10 months ago by alanfrys.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • @alanfrys, If you aren’t concerned with what role the user has (basic roles:administrator, editor, author, subscriber) but only if the user is logged in (which is typically a subscriber) then try the … wait for itis_user_logged_in() function.

    Example:

    
    if ( is_user_logged_in() ) {
        [
        whatever template part is used to get these elements:
        <span class="details"></span>
        <span class="details"></span>
        <span class="details"></span>
        <span class="details"></span>
        <div class="woocommerce-product-details__short-description"></div>
    ]
    } else {
    echo '<a href="/wp-login.php">Login</a> to see details.';
    }
    

    Hope that helps.

    To clarify, the brackets [ ] and their contents should not be used.

    replace with something more along the lines of php like
    get_template_part('template-parts/item-details');

    So that would be:

    if ( is_user_logged_in() ) {
        get_template_part('template-parts/item-details');
    } else {
    echo '<a href="/wp-login.php">Login</a> to see details.';
    }
    • This reply was modified 4 years, 10 months ago by Nic Winn.
    Thread Starter alanfrys

    (@alanfrys)

    Thank you for the answer!

    // showing on single product page
    add_action(‘woocommerce_single_product_summary’,’show_product_code’,13);

    function show_product_code(){
    global $product;
    if ( empty( $product ) ) {
    return;
    }

    But im confused, that code its what i want to hide for non log in users. Below that there are many options, so woocommerce_single_product_summary its the template? i dont know how can i add that and hide the information, i tried but doesnt work obviusly there are thing im doing wrong.
    If you can help me could be amazing, maybe its dificult to me because i am not a developer.

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Restrict content for visitors’ is closed to new replies.