• Resolved Jon Gledhill

    (@cbctraining)


    Hi Teodor, I’ve created a new support request as you suggested.

    Let me try to clarify my request and also answer your questions from the other post.

    I wish to display a lock icon next to a post title only when a post is protected.

    Currently, I am developing a training website (test site) using the Knowall KB WordPress Theme and the LearnDash plugin.

    As I need to have several membership tiers on my site and need them to work happily alongside my LearnDash courses I need to use the WooCommerce Memberships Plugin. This allows me to use a couple of plugins that will really help with the administration of the website (Group Registration for LearnDash).

    I have contacted the WooCommerce developers and the developers of the theme but they just advised I speak to a WordPress Support Agency. I did this and I’m still waiting for a response.

    After seeing your post reply on this forum which detailed exactly how to achieve this with your own plugin I had hoped that the general basis of how it worked might transfer to another plugin/theme with a few tweaks to the code?

    I have tried for many hours to make it work myself with no luck. I am not a developer, unfortunately.

    I hoped you might be interested in assisting me with this?

    • This topic was modified 7 years, 9 months ago by Jon Gledhill. Reason: Make main question more prominent
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi Jon,

    Thank you for the additional details.

    1. Create an empty plugin like this: https://gist.github.com/sareiodata/76f701e01db6685829db

    2. Add the following code to the end of it:

    /*
     * Filter to display a Locked Font Awesome Icon next to the Title of a Restricted Post/Page
     * Works with WooCommerce Memberships plugin
     */
    
    add_filter('the_title', 'pmsc_add_icon_next_to_restricted_post', 10, 2);
    
    function pmsc_add_icon_next_to_restricted_post($post_title, $post_id) {
        if (is_admin()) {
            return $post_title;
        }
        if (wc_memberships_is_post_content_restricted ($post_id)) {
            return '<i class="fa fa-lock" aria-hidden="true"></i>' . ' ' . $post_title;
        }
        return $post_title;
    }

    3. Install this plugin via FTP (copy it inside wp-content/plugins) or create a zip archive with it and install it via the WordPress plugin upload functionality

    Also make sure the post is restricted based on a WooCommerce Subscription Plan. For the font awesome icon install a plugin like WP Font Awesome.

    Let me know if the custom code works.

    Best regards,

    Thread Starter Jon Gledhill

    (@cbctraining)

    Hi Teodor

    Thank you so much for this generous assistance!

    The instructions above have resulted in the icon appearing next to the post-title of all posts which have been restricted based on a WooCommerce Subscription Plan.

    I see from my description above that I may not have explained clearly enough what I was hoping to achieve though.

    I really need an icon to only appear if that user does not have permission to access that post. As I will have a free tier on my website every post will, in essence, be restricted based on a WooCommerce Subscription Plan. By this logic currently, all of the posts will appear with a lock icon.

    Can you suggest an additional solution for this?

    I massively appreciate all of the time and efforts you are giving for this and would be happy to make a donation/reimburse you for your time.

    Best wishes
    Jon

    Thread Starter Jon Gledhill

    (@cbctraining)

    I’ve found a few posts that seem to lead towards what I’m trying to achieve – I hoped they might be of help.

    I think it might involve this?

    if( wc_memberships_is_user_active_member( $membership_plan ) )

    codedump.io
    hotexamples.com
    stackoverflow.com
    ask.warrior.pk
    https://techqa.info/programming/question/37714426/woocommerce-memberships:-conditional-to-check-a-page-access
    https://www.technoedu.com

    Thanks so much!!

    Best wishes
    Jon

    Thread Starter Jon Gledhill

    (@cbctraining)

    Hi Teodor

    I wanted to say a thank you for all your help with this. I have found someone to help me the changes to the code.

    https://github.com/skyverge/wc-plugins-snippets/blob/master/woocommerce-memberships/frontend/add-restricted-post-lock-icon.php

    Thanks for all your help!

    Best wishes
    Jon

    Hi Jon,

    I am glad that you managed to adjust the code as you want and it works.

    Have a great day.

    Best regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Support from Teodor request (Displaying a lock icon only on restricted content)’ is closed to new replies.