Add a Lock Icon to WooCommerce Memberships Restricted Posts

,


To add the icon, we’ll filter the_title to adjust the post title. We’ll need to (a) be sure avoid running this in the WordPress admin, and (b) show this icon if access is restricted or delayed.

Add the following code in your functions.php file


function sv_wc_memberships_add_post_lock_icon( $title, $post_id ) {

    if ( is_admin() ) {
        return $title;
    }

    // show the lock icon if the post is restricted, or access is delayed
    if (   ! current_user_can( 'wc_memberships_view_delayed_post_content',    $post_id )
        || ! current_user_can( 'wc_memberships_view_restricted_post_content', $post_id ) ) {

        $title = "<i class='fa fa-lock' aria-hidden='true'></i> {$title}";
    }

    return $title;
}
add_filter( 'the_title', 'sv_wc_memberships_add_post_lock_icon', 10, 2 );




Related Post


Latest Post


Recent Posts Widget

Make sure to never miss a thing...

Get the latest news from the creative industry along with other creative goodies, conveniently delivered to social media.