Show total number of requests received by a user in custom menu

I have added this filter to add a custom menu and URL but it is just showing the number of requests submitted by a user on the user dashboard but not in the receiver dashboard.

I am stuck here and need help.

Thanks!

add_filter(

'hivepress/v1/menus/user_account',

function ( $menu ) {

    if ( is_user_logged_in() ) {

        if ( hivepress()->request->get_context( 'request_count' ) >= 0 ) {

            $item_args = [

                'label'  => 'Requests',

                'url'    => home_url().'/request',

                '_order' => 123,

            ];



            $item_meta = hivepress()->request->get_context( 'request_count' );



            if ( $item_meta ) {

                $item_args['meta'] = $item_meta;

            }



            $menu['items']['requests_edit'] = $item_args;

        }

    }

    return $menu;

},

1000

);

image

Please check the image this is the submitter dashboard

image

This is the receiver dashboard and I am unable to add the count here with the menu. It should show 3 as in the submitter dashboard.

Hi,

Please try this PHP snippet:

add_filter(

    'hivepress/v1/menus/user_account',

    function ( $menu ) {

        if ( is_user_logged_in() ) {

             $item_args = [

                   'label'  => 'Requests',

                    'url'    => home_url().'/request',

                    '_order' => 123,
                ];
   
    $item_meta = intval(hivepress()->request->get_context( 'request_count' ));
    
    $vendor_id = \HivePress\Models\Vendor::query()->filter(['user' => get_current_user_id()])->get_first_id();
   
    if($vendor_id){
     $received_request = \HivePress\Models\Request::query()->filter([
      'vendor'       => $vendor_id,
     ])->get_count();
     
     $item_meta += intval($received_request);
    }
    
                if ( $item_meta ) {

                    $item_args['meta'] = $item_meta;

                }


                $menu['items']['requests_edit'] = $item_args;

        }

        return $menu;

    },

    1000

);

Please note that it can require further customization.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.