How to get course_id of a woocommerce product page?

17 Views Asked by At

I have to remove a student from a Sensei Pro course if they have completed the course. When they try to purchase the course again and WooCommerce generates an error preventing them from purchasing because they already have the course, I check if they have already completed the course, and if so, I remove them from the course. So far, I can get the course ID, which is the same as the page ID, but I can't get the course related to that product.

function alterar_mensagem_restricao_compra( $error ) {
    // Verifica se a mensagem padrão está presente
    if ( strpos( $error, 'Você já possui todos os cursos associados a este produto' ) !== false ) {       
       
        global $post;
        $user = wp_get_current_user();
        //$status = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user->ID ) );
        $produtos = Sensei_Course::get_product_courses(168);

        //$course = get_post_meta($post->ID, '_related_course', true);
        //return $status;
        if($produtos){
            
             $error = 'Você ainda tem redações a serem enviadas/corrigidas. Você precisa enviar e receber todas as redações do pacote para poder adiquirir o mesmo pacote ou você pode adiquirir um pacote diferente.'.$status;
        }else{
            $error = 'Você ainda tem redações ';
        }
       
    }
    return $error;
}
add_filter( 'woocommerce_add_error', 'alterar_mensagem_restricao_compra' );
0

There are 0 best solutions below