fbpx

How can we help?

Hide/Show registration button on specific events

Not all your events need a Registration Button/ tab. So here is the solution to remove the registrations tab/button in WP Event Manager.

There are certain events where the organizer does not want the people to register for the event and hence does not requires a registration tab.

Hide/Show registration button on specific events

The following code can be implemented in the Functions.php file of the child theme to disable or enable the Registration tab on specific events.

  1. Open your child theme function.php.
  2. Add this code:
    <?php
    /* Register meta box(es).
    */
    function wpdocs_register_meta_boxes() {
             add_meta_box( 'registration-button-settings-meta-box', __( 'Registrations button meta box', 'wp-event-manager' ), 'wpdocs_my_display_callback', 'event_listing' ,'side');
              }
    add_action( 'add_meta_boxes', 'wpdocs_register_meta_boxes' );
      
    /* Meta box display callback.
    @param WP_Post $post Current post object.
    */
      
          function wpdocs_my_display_callback( $post ) {
      
    // Display code/markup goes here. Don't forget to include nonces!
      
           $show_regi_btn = get_post_meta($post->ID,'_show_hide_registration_button',true);
           ?>
             <label for="wporg_field">Hide registrations button</label>
             <input type="checkbox" name="show_hide_registration_button" id="show_hide_registration_button" <?php 
                if(isset($show_regi_btn) && $show_regi_btn == 1) echo 'checked="checked"';?> value="1">
           
          <?php }
    ?>
      
    <?php
    
        // Save your meta box content
        add_action( 'save_post', 'wpdocs_save_meta_box' );
      
    /* Save meta box content.
    @param int $post_id Post ID
    */
      
    function wpdocs_save_meta_box( $post_id ) {
    
    // Save logic goes here. Don't forget to include nonce checks!
    update_post_meta($post_id,'_show_hide_registration_button',$_POST['show_hide_registration_button']);
    
    }
      
    /**
     * registration_limit_restriction
     * @param $method,$post
     * @return $method
     * @since 3.1.11
     */
    function your_child_theme_registration_disable($method,$post){
    
        $disable_button = get_post_meta($post->ID,'_show_hide_registration_button',true);
    
        //disable button if settings in event meta box
        if( $disable_button == 1){
            //echo '<div class="event-manager-registrations-registered-notice wpem-alert wpem-alert-warning">'.__('Disabled button','wp-event-manager-registrations').'</div>';
             return false;
        }else{
            return $method;
        }
          
    }
    add_filter('display_event_registration_method','your_child_theme_registration_disable',90,2);
    add_filter('get_event_registration_method','your_child_theme_registration_disable',90,2);
    ?>
    
Was this article helpful?
How can we improve this article?
Quick Links