Home › Forums › Legacy Support › Support queries › How-to & Troubleshooting › Custom course nav to hide price sttings
- This topic has 7 replies, 3 voices, and was last updated 2 years, 6 months ago by Veronica.
Viewing 8 posts - 1 through 8 (of 8 total)
-
AuthorPosts
-
November 5, 2021 at 4:34 pm #374104angelhc3SpectatorI 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?November 6, 2021 at 1:39 pm #374153Anshuman SahuKeymasteryes 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);
November 8, 2021 at 11:56 pm #374321angelhc3SpectatorI have tried your code. But the screen goes blank when i click on Accesibility tab. can you check the code?November 9, 2021 at 1:56 pm #374370Anshuman SahuKeymasterHere 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);
November 9, 2021 at 3:12 pm #374375angelhc3SpectatorThank 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 thanksNovember 10, 2021 at 12:49 pm #374417VeronicaModeratorin code course_id is course's ID user_id is User's ID $setting['id'] is product's IDNovember 11, 2021 at 10:53 pm #374498angelhc3SpectatorI 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 ThanksNovember 12, 2021 at 10:26 am #374520VeronicaModeratorhi 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 -
AuthorPosts
Viewing 8 posts - 1 through 8 (of 8 total)
- The topic ‘Custom course nav to hide price sttings’ is closed to new replies.