Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Hide GB Block When Visitor Enrolled In Lifter LMS Course

  • I have maybe kind of a unique issue:

    On course pages for a site using GB and Lifter LMS, I want to display a login button if the visitor is not logged in and also an Enroll Now button if the user is either not logged in or not enrolled in that particular course.

    Displaying the login button when a website visitor is not logged in will be relatively easy.

    The challenge is the Enroll Now button.

    I can use the standard WordPress button block, and there is an Enrollment Visibility dropdown setting in the right settings column (see this screenshot). This functionality allows me to hide the button if the user is logged in and already enrolled in that particular course. I think this Enrollment Visibility setting comes from the Lifter LMS plugin. The problem with using the standard WordPress button block is the lack of dynamic capabilities. I want to insert these buttons with a GP element and dynamically pull the enroll URL from a course custom field. Unless I am missing something, I’m not sure that is easily done using the standard WP button block.

    Using the GB button block, I can dynamically get the URL from the course custom field. But with the GB button block, the Enrollment Visibility setting does not appear in the right settings sidebar.

    So, either way, I am missing out on a key capability. Any thoughts on how I could get this to work?

    Is there any code snippet that might allow the Lifter LMS Enrollment Visibility settings to also apply to GB blocks?

    Or is there a way to pull a URL from a custom field dynamically into the core WordPress button block?

  • Hi Brent,

    The way I would do this is the following steps:

    1. Create a custom Hook.

    Portable hook code:

    function your_shortcode($atts, $content = null) {
          ob_start();
          do_action('hook_name');
          return ob_get_clean();
    }
    add_shortcode('portable_hook', 'your_shortcode');

    Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

    Adding it through Code Snippets should work.

    After adding this PHP, you may add the shortcode as such: https://share.getcloudapp.com/ApuJGooG

    Then you can now hook to hook_name through custom hook.

    Example: https://share.getcloudapp.com/eDu5xKLX

    2. Create a Block Element – Hook. Add the Button here. Set the hook of this element to your custom Hook.

    3. Finally, create a generate_block_element_display code to disable the Block Element depending if the user is Logged in to LMS or enrolled in a course (You’ll need to check with your plugin if there is a Conditional Statement that can be used for this – something like if(user_is_enrolled('MY-COURSE'))).

    Reference: https://docs.generatepress.com/article/generate_element_display/

    The important thing to make this work is the conditional statement from LMS.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.