Okay
  Public Ticket #3398836
Conditional Code for B2B users only
Closed

Comments

  • Jon Marchand started the conversation

    I was helped with a code snippet the other day to add an additional menu item inside the my account section of B2B (sales kit). I need to make this code snippet execute conditionally based on the group of the user (b2b Wholesale users only).

    The code is below. Is this possible? 

    function b2bking_add_sales_kit_endpoint() {
        add_rewrite_endpoint( 'sales-kit', EP_ROOT | EP_PAGES );
    }
      
    add_action( 'init', 'b2bking_add_sales_kit_endpoint' );
      
    function b2bking_sales_kit_query_vars( $vars ) {
        $vars[] = 'sales-kit';
        return $vars;
    }
      
    add_filter( 'query_vars', 'b2bking_sales_kit_query_vars', 0 );
      
      
    function b2bking_add_sales_kit_link_my_account( $items ) {

        $i = 1;
       
        $items = array_slice($items, 0, $i, true) +
        array('sales-kit' => 'Sales Kit') + 
        array_slice($items, $i, count($items)-$i, true);

        return $items;
    }
      
    add_filter( 'woocommerce_account_menu_items', 'b2bking_add_sales_kit_link_my_account' );
      
      
    function b2bking_sales_kit_content() {
       echo '

    Sales Kit

    Click on the items below to retrieve your sales kit

    '


       ;
    }
      
    add_action( 'woocommerce_account_sales-kit_endpoint', 'b2bking_sales_kit_content' );



  •  2,285
    WebWizards replied

    Hi Jon,

    I believe we discussed this earlier via Facebook Chat,

    For future reference, developer documentation is found at  https://woocommerce-b2b-plugin.com/docs/developer-documentation-hooks-functions-custom-code/


    The following functions will be useful for this:

    • b2bking()->is_b2b_user($user_id) - checks if user is B2B
    • b2bking()->get_user_group($user_id) - returns the group ID of a user


    Kind regards,

    Stefan