Created
February 2, 2026 08:13
-
-
Save woogist/f216760d972279936b128fe2ed6768b1 to your computer and use it in GitHub Desktop.
[WooCommerce Memberships] Display a FontAwesome lock icon next to the post title if a member does not have access
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php // only copy if needed | |
| /** | |
| * Display a FontAwesome lock icon next to the post title if a member does not have access | |
| * with WooCommerce Memberships. | |
| * | |
| * REQUIRES FontAwesome to be loaded already | |
| * | |
| * @param string $post_title the post title | |
| * @param int $post_id the WordPress post ID | |
| * @return string the updated title | |
| */ | |
| 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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment