LearnDash integrates well with WooCommerce. But there are certain caveats. When an order is placed for a LearnDash course, from WooCommerce, it only shows regular WooCommerce order data with regular WooCommerce products, which were just purchased. But it doesn’t show anything about the purchased courses. If we can show some information or at least course links, so they can be accessed easily, it will be quite handy for your users.
To achieve this, we will push our modifications with woocommerce_after_order_details
action hook. This will show our modifications after the order details section of the thank you page.
function careless_purchased_course_details( $order ) {
//get items and products
$items = $order->get_items();
if ( $items ) { ?>
<section class="ld-woocommerce-course-details">
<h2 class="ld-woocommerce-course-details__title">Ordered Courses</h2>
<ul>
<?php foreach ( $items as $item ) {
$course_ids = get_post_meta( $item->get_product_id(), '_related_course', true );
if ( is_array( $course_ids ) ) {
foreach ( $course_ids as $course_id ) {
echo '<li><a href="' . get_the_permalink( $course_id ) . '" target="_blank">' . get_the_title( $course_id ) . '</a>';
}
}
} ?>
</ul>
</section>
<?php }
}
add_action( 'woocommerce_after_order_details', 'careless_purchased_course_details', 10, 1 );
Code goes in the functions.php
file of your active theme.