<?php
$args = array(
'post_type' => 'course',
);
$query = new WP_Query($args);
while($query->have_posts()) {
$query->the_post();
$course_id = get_the_ID();
$product_id = wpc_get_connected_product_id( $course_id );
$current_user = wp_get_current_user();
$link = get_the_permalink();
// check if the course is connected to a WooCommerce product.
if( wpc_get_connected_product_id( $course_id ) !== false ) {
// check that the customer has bought the course.
$has_bought = wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id );
// if the customer has bought the course, show it.
if( $has_bought !== false ) {
echo '<a href="' . $link . '">' . get_the_title() . '</a>';
}
}
}
wp_reset_postdata();
?>