'How to restrict page access for non-tagged users

As you can read from the title, I'm really struggling to restrict non-tagged users from a specific page. I currently have a default blog called 'news' and a blog called 'course' for customers who bought a membership from the store. Those customers are getting tagged as 'member'.

In main-blog.liquid I already made an if statement which keeps customers with no 'member' tag outside. This is not so efficient since normal customers are also getting blocked from the default 'news' blog.

My code:

{% if customer.tags contains 'member' %}
 {%- paginate blog.articles by 6 -%}
  <div class="main-blog page-width section-{{ section.id }}-padding">
   <h1 class="title--primary">{{ blog.title | escape }}</h1>

   <div class="blog-articles {% if section.settings.layout == 'collage' %}blog-articles--collage{% endif %}">
   {%- for article in blog.articles -%}
   <div class="blog-articles__article article">
        {%- render 'article-card',
          article: article,
          media_height: section.settings.image_height,
          media_aspect_ratio: article.image.aspect_ratio,
          show_image: section.settings.show_image,
          show_date: section.settings.show_date,
          show_author: section.settings.show_author,
          show_excerpt: true 
        -%}
      </div>
   {%- endfor -%}
   </div>

   {%- if paginate.pages > 1 -%}
    {%- render 'pagination', paginate: paginate -%}
   {%- endif -%}
  </div>
 {%- endpaginate -%}
{% endif %}

How can I code in a way that normal customers can only see the default 'news' blog and the tagged customers see both 'news' and 'course' blogs?



Solution 1:[1]

You'll need real blog handles but this should do the work.

{% case blog.handle %}

{% when 'course' %}

    {% if customer.tags contains 'members' %}
        Display blog articles
    {% else %}
        Login, subscribe, etc...
    {% endif %}

{% else %}

    Display blog articles

{% endcase %} 

Solution 2:[2]

how about php code

function custom_wc_translations($translated){
    $text = array(
    'Your order' => 'Your new phrase',
    'any other string' => 'New string',
    );
    $translated = str_ireplace(  array_keys($text),  $text,  $translated );
    return $translated;
}

add_filter( 'gettext', 'custom_wc_translations', 20 );

or

<script type="text/javascript">
(function($) {
$(document).ready(function() {
$('#your_my_order_element_id').html('Your New string');
//$('.your_my_order_element_class').html('Your New string');
});
})(jQuery);
</script>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alice Girard
Solution 2 ?????jakub