Okay
  Public Ticket #2971740
Restrict access for b2c to one specific page
Closed

Comments

  •  3
    dym0ckr started the conversation

    I would like to  separete view of category menu for b2b and b2c clients. 

    So i decided to create specific page with diffrent  sidebar wiget with category menu fo b2b clients,  but last puzzel  i need to do so is restric  access for b2c clients to this b2b site. How can na achive this?

  •  2,218
    WebWizards replied

    Hi there,

    Thank you for purchasing our plugin,


    My suggestion is: If the user is B2C and they are trying to view the B2B page, you can redirect them to another page.

    You can do that with this code snippet:

    add_action( 'template_redirect', function(){
        $b2b_page_id = 1234; // replace with your page ID
        // check if user is B2C
        $user_id = get_current_user_id();
        $is_b2b = get_user_meta($user_id,'b2bking_b2buser', true);
        // if B2C user
        if ($is_b2b !== 'yes'){
            // if page is b2b page, redirect
            $current_page = get_queried_object_id();
            if ($current_page == $b2b_page_id ){
                // redirect away
                wp_redirect( get_permalink( wc_get_page_id( 'shop' ) ) ); // redirect to shop page
            }
        }
        
    }, 1000);
    

    This snippet can be added to functions.php, or by following our guide here: https://woocommerce-b2b-plugin.com/docs/how-to-add-a-snippet-php-or-js/


    You would need to replace 1234 with the ID of your page. To get the page ID you can edit the page, and the number in the URL is the ID (if the URL says "?post=123", the ID is 123)


    Let me know if I can help with anything, or if you have any questions,

    Kind regards,

    Stefan


  •  3
    dym0ckr replied

    Thanks for this ,  i will use it.

    But now i'm thinking that this concept isn't enough,  

     my product category menu is different for B2B and B2C,  ( first half of product categories menu is for B2B and the second half is for  B2C),

    If i redirect B2C customer  from B2B webiste, all other woocommerce sites still contain  Product Categories Menu for both (b2b and b2c).

     I would like to find a way to  implement something like  ( if  logged user = b2c ) css  .ProductCategoriesMenu (visibility: hidden).

    Thanks again for help,  

    Plugin is fantastic i'm glad that i decided to buy it.

    UPDATE:

    i found this:

     https://woocommerce-b2b-plugin.com/docs/shortcode-to-restrict-content-to-b2b-b2c-user-groups-specific-users/

  •  2,218
    WebWizards replied

    Thank you for the kind words,

    Glad to hear you found that article. Right, you can use either the visibility shortcode, or the Body classes to hide items for b2b / b2c / specific groups, etc.

    Let me know if there's anything I can help with,