Woocommerce – Remove cart button depending product (post) status

Finally find my solution after a few day.

In case someone try to do the same

function test_expired_product(){
    $id = get_the_ID();
    $post_status = get_post_status($id);
    $terms= array('cursus-annuel');


    if ($post_status === 'expired' || $post_status === 'canceled') {
        //echo $id;             // working
        //echo $post_status;    // working

        add_filter('woocommerce_is_purchasable', '__return_false');
        add_action( 'woocommerce_single_product_summary', 'expired_product_message', 20 );
        return;
    }

    if( has_term( $terms, 'product_cat' ) ){
        add_filter('woocommerce_is_purchasable', '__return_false');
        add_action( 'woocommerce_single_product_summary', 'unpurchasable_product_message', 20 );
        return;
    }
}
add_action('wp','test_expired_product');

function expired_product_message() {
    echo '<p style="color:#e00000;">Ce produit n\'est plus disponible.</p>';
}

function unpurchasable_product_message() {
    echo '<p style="color:#e00000;">Ce produit ne peut pas être acheté en ligne. Veuillez nous contacter afin de reserver ce cours.</p>';
}