[CoursePress Pro] Certificate

I have created a prerequisite course for verification purposes. How can I disable the certificate for just that one course?

  • Adam Czajczyk

    Hi Anna Bouhail

    I hope you're well today and thank you for your question!

    That is currently not possible out of the box, I'm afraid. I have, however, passed this question to our developers so they could check if there's any reasonably simple way to overcome this.

    Please note though: it might take them a bit longer to respond than it takes us here on support forum as they are dealing with complex issues on daily basis. Also, I'm not able to guarantee the solution until (and unless) they confirm that there's a workaround.

    Please keep an eye on this ticket for further information and I'd apologize some patience. We'll update you here as soon as we got some feedback on this.

    Kind regards,
    Adam

  • Panos

    Hi Anna Bouhail ,

    There is no option nor direct filter for this I'm afraid. I can provide a snippet that would filter the the_content in order to remove the certificate download links.

    You can add the following in a mu-plugin, but it would probably need some further tweaking:

    add_filter( 'the_content', function( $content ){
    
    	if( ( is_admin() && ! wp_doing_ajax() )  ) {
    		return $content;
    	}
    
    	global $post;
    
    	$courses_without_certificate = array( 7891, 7900 );
    
    	if ( $post instanceof WP_Post ) {
    
    		$course_id = null;
    
    		switch ( $post->post_type ) {
    			case 'course' :
    			case 'unit_archive' :
    				$course_id = $post->ID;
    				break;
    			case 'unit' :
    				$course_id = $post->post_parent;
    				break;
    			case 'course_notifications_archive' :
    				$_course_id = str_replace( 'notifications_archive_', '', $post->post_name );
    				if ( is_numeric( $_course_id ) ) {
    					$course_id = $_course_id;
    				}
    				break;
    			case 'course_discussion_archive' :
    				$_course_id = str_replace( 'discussion_archive_', '', $post->post_name );
    				if ( is_numeric( $_course_id ) ) {
    					$course_id = $_course_id;
    				}
    				break;
    			case 'course_workbook' :
    				$_course_id = str_replace( 'workbook_', '', $post->post_name );
    				if ( is_numeric( $_course_id ) ) {
    					$course_id = $_course_id;
    				}
    				break;
    			case 'course_grades_archive' :
    				$_course_id = str_replace( 'grades_archive_', '', $post->post_name );
    				if ( is_numeric( $_course_id ) ) {
    					$course_id = $_course_id;
    				}
    				break;
    
    		}
    
    		if ( is_null( $course_id ) || ! in_array( $course_id, $courses_without_certificate ) ) {
    			return $content;
    		}
    
    		if ( strpos( strtolower( $post->post_title ), 'congratulations') !== false) {
    			return '<h3>Congratulations! You have successfully completed and passed Test Course!</h3>';
    
    		}
    
    		$doc = new DOMDocument();
    		$doc->loadHTML( $content );
    
    		$selector = new DOMXPath( $doc );
    		foreach($selector->query('//li[contains(attribute::class, "submenu-certificate")]') as $e ) {
    		    $e->parentNode->removeChild($e);
    		}
    
    		return $doc->saveHTML($doc->documentElement);
    	}
    
    }, 20 );

    You can add the course ids in the array:
    $courses_without_certificate = array( 7891, 7900 );

    I know you asked only one, but this gives a bit more flexibility.

    It should remove the certificate links for that course's menu. It should also remove the certificate link from the completion page. If it still shows in completion page, try setting here:
    if ( strpos( strtolower( $post->post_title ), 'congratulations') !== false) {
    a word that is included in the title of the Course Completion Page instead of congratulations

    Hope this helps :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.