remove time,price from widget based on category

Home Forums Legacy Support Support queries How-to & Troubleshooting remove time,price from widget based on category

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #69364
    chinolz
    Spectator
    Hi 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; } }
    #69463
    H.K. Latiyan
    Participant
    instead of get_the_category try using : global $post; get_the_terms( $post, 'course-cat');
    #69837
    chinolz
    Spectator
    add_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>'; } }
    #69838
    chinolz
    Spectator
    This reply has been marked as private.
    #69985
    H.K. Latiyan
    Participant
    get_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.
    #70207
    chinolz
    Spectator
    This reply has been marked as private.
    #70326
    H.K. Latiyan
    Participant
    Try 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; }
    #70345
    chinolz
    Spectator
    nope the code didnt do anything
    #70458
    H.K. Latiyan
    Participant
    The code works fine on our test setup. Please make sure the category name is case sensitive and clear the cache before checking..
Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘remove time,price from widget based on category’ is closed to new replies.