Custom course nav to hide price sttings

Home Forums Legacy Support Support queries How-to & Troubleshooting Custom course nav to hide price sttings

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #374104
    angelhc3
    Spectator
    I would like to hide Product creation setting based on User Role. or member type I have seen this code: https://gist.github.com/99manish/a4b13d00fe6a16c10760ed36279b10ed It is almost what I need, I have added some lines: add_action('wplms_course_creation_tabs',function ($settings){ if(current_user_can('manage_options')) return $settings; foreach ($settings['course_pricing']['fields'] as $key => $setting) { if($setting['id']=='vibe_product') { $user = wp_get_current_user(); if ( in_array( 'Instructor', (array) $user->roles ) ) { //The user has the "instructor" role unset($settings['course_pricing']['fields'][$key]); break; } } } return $settings; },999999,1); Can you help?
    #374153
    Anshuman Sahu
    Keymaster
    yes now user_id is passed in the filter itself to check as wp_current_user wont work ; new code :
    add_action(‘wplms_course_creation_tabs',function ($settings,$course_id,$user_id){
    $user = get_userdata( $user_id );
    
    // Get all the user roles as an array.
    $user_roles = $user->roles;
    
    foreach ($settings['course_pricing']['fields'] as $key => $setting) {
    if($setting['id']=='vibe_product')
    {
    
    // Check if the role you're interested in, is present in the array.
     if(in_array( 'instructor', $user_roles, true )){
    	unset($settings[‘course_pricing'][‘fields'][$key]);
    
    }
    
    }
    }
    return $settings;
    },999999,3);
    #374321
    angelhc3
    Spectator
    I have tried your code. But the screen goes blank when i click on Accesibility tab. can you check the code?
    #374370
    Anshuman Sahu
    Keymaster
    Here is the correct and tested code :
    add_action('wplms_course_creation_tabs',function ($settings,$course_id,$user_id){
        $user = get_userdata( $user_id );
    
    // Get all the user roles as an array.
        $user_roles = $user->roles;
        $settingss = [];
        foreach ($settings['course_pricing']['fields'] as $key => $setting) {
            if(in_array( 'administrator', $user_roles, true )){
                if($setting['id']!=='vibe_product'){
                     $settingss[] = $setting;
                }
            }
        }
        $settings['course_pricing']['fields'] = $settingss;
        return $settings;
    },999999,3);
    #374375
    angelhc3
    Spectator
    Thank a lot it is working. Last question. Can you help me identifying this. for example. course_pricing ID is for pricing. What are the others ID thanks
    #374417
    Veronica
    Moderator
    in code course_id is course's ID user_id is User's ID $setting['id'] is product's ID
    #374498
    angelhc3
    Spectator
    I was testing your code and then realised that it is not working at all. When login as instructor works, but if the Admin wants to edit, All Accesibility settings dissapear it hapens for the Admin's course also. can you check? Login as Admin Refer: https://screencast-o-matic.com/watch/crXXYiVIVJD Login as instructor: https://screencast-o-matic.com/i/crXXY2VIVdW Thanks
    #374520
    Veronica
    Moderator
    hi check this: http://prntscr.com/1z9x5c9 you need to change the role according to if you want to hide it for instructor then change it to instructor
Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Custom course nav to hide price sttings’ is closed to new replies.