Home › Forums › Legacy Support › Support queries › How-to & Troubleshooting › remove time,price from widget based on category
- This topic has 8 replies, 2 voices, and was last updated 8 years, 4 months ago by H.K. Latiyan.
Viewing 9 posts - 1 through 9 (of 9 total)
-
AuthorPosts
-
September 7, 2016 at 9:17 am #69364chinolzSpectatorHi i used this code in order to remove time and price from widget sidebar for a specific category, however the code seems to remove it from all course categories. Any idea what might have went wrong add_filter('wplms_course_details_widget',array($this,'remove_wplms_course_details_widget')); function remove_wplms_course_details_widget($course_details){ $cat = get_the_category(); $cat = $cat[0]; if($cat->cat_name == "Resources"){ $key = 'time'; // Set $key value from price,precourse,time,level,seats,badge,certificate unset($course_details[$key]); return $course_details; } }September 7, 2016 at 2:52 pm #69463H.K. LatiyanParticipantinstead of get_the_category try using : global $post; get_the_terms( $post, 'course-cat');September 9, 2016 at 9:41 am #69837chinolzSpectatoradd_filter('wplms_course_details_widget',array($this,'remove_wplms_course_details_widget')); function remove_wplms_course_details_widget($course_details){ global $post; $cat = get_the_terms( $post, 'course-cat'); if($cat == "resource"){ $key = 'price'; // Set $key value from price,precourse,time,level,seats,badge,certificate unset($course_details[$key]); return $course_details; } } changing to this didnt work, still it removed from all categories i used a similar code which works perfectly fine (removing the button to Researces category. add_action('wplms_the_course_button','wplms_custom_hide_button'); function wplms_custom_hide_button(){ $cat = get_the_category(); $cat = $cat[0]; if($cat->cat_name == "Resources"){ echo '<style>.course_button{display:none !important;}</style>'; } }September 9, 2016 at 9:42 am #69838chinolzSpectatorThis reply has been marked as private.September 10, 2016 at 8:52 am #69985H.K. LatiyanParticipantget_the_terms() function execpts the ID and returns the array, therefore you cannot directly check if it is resorces or not. Use the bellow code in your wplms-customizer.php file present in your wplms customizer plugin: add_filter('wplms_course_details_widget','remove_wplms_course_details_widget'); function remove_wplms_course_details_widget($course_details){ global $post; $terms = get_the_terms( $post->ID, 'course-cat'); if(empty($terms)){ return $course_details; } foreach ($terms as $term) { $cat = $term->name; break; } if($cat == "Technology"){ $key = 'price'; unset($course_details[$key]); return $course_details; } return $course_details; } NOTE: Change the category here accordingly, also note that the name is case sensitive therefore add the name correctly.September 12, 2016 at 1:32 pm #70207chinolzSpectatorThis reply has been marked as private.September 13, 2016 at 11:06 am #70326H.K. LatiyanParticipantTry using the bellow code instead of the above one: add_filter('wplms_course_details_widget','remove_wplms_course_details_widget'); function remove_wplms_course_details_widget($course_details){ global $post; $terms = get_the_terms( $post->ID, 'course-cat'); if(empty($terms)){ return $course_details; } $category = array(); $cat = ''; foreach ($terms as $term) { $category[] = $term->name; } if(in_array('Technology', $category)){ $cat = 'Technology'; } if($cat == "Technology"){ $key = 'price'; unset($course_details[$key]); return $course_details; } return $course_details; }September 13, 2016 at 11:55 am #70345chinolzSpectatornope the code didnt do anythingSeptember 14, 2016 at 10:53 am #70458H.K. LatiyanParticipantThe code works fine on our test setup. Please make sure the category name is case sensitive and clear the cache before checking..
-
AuthorPosts
Viewing 9 posts - 1 through 9 (of 9 total)
- The topic ‘remove time,price from widget based on category’ is closed to new replies.