• Hi sir,in this forum i found code for “allow register user to dispaly contacts” its working fine but i want this for perticular categories. how to do this ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,

    can you point me to the code snippet you are using?

    Thread Starter rajs1010

    (@rajs1010)

    
    add_filter( "wp", "loggedin_members_only_init", 50 );
    function loggedin_members_only_init() {
        if( is_singular( 'advert' ) && get_current_user_id() < 1 ) {
            remove_action( 'adverts_tpl_single_bottom', 'adverts_single_contact_information' );
            remove_action( 'adverts_tpl_single_bottom', 'adext_contact_form' );
            remove_action( 'adverts_tpl_single_bottom', 'adext_bp_send_private_message_button', 50 );
    
            add_action( 'adverts_tpl_single_bottom', "loggedin_members_only", 5 );
        }
    }
    function loggedin_members_only( $post_id ) {
        $flash = array( "error" => array(), "info" => array(), "warn" => array() );
        $flash["warn"][] = array(
            "message" => sprintf( "Only logged-in user can contact sellers. <a href=\"%s\">Login</a> or <a href=\"%s\">Register</a>", wp_login_url( get_permalink( get_the_ID() ) ), wp_registration_url() ),
            "icon" => "adverts-icon-block"
        );
        adverts_flash( $flash );
    }
    Plugin Author Greg Winiarski

    (@gwin)

    If you want this to run only when the category name/slug is for example cats or dogs then at the beginning of the loggedin_members_only_init function you can add the code below

        $run_only_in = [ "cats", "dogs" ];
        $do_run = false;
        if( ! is_singular( 'advert' ) ) {
          return;
        } 
        $terms = wp_get_post_terms( get_the_ID(), "advert_category" );
        $slugs = [];
        foreach( $terms as $term ) {
            $slugs[] = $term->slug;
        }
        foreach( $slugs as $slug ) {
            if( in_array( $slug, $run_only_in ) ) {
                $do_run = true;
            }
        }
        if( ! $do_run ) {
            return;
        }
        

    On the first line you can list all the categories in which the whole code should be run.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Only allow register user to contact seller for perticular category’ is closed to new replies.