search expand
Skip to content
Careless Dev

Careless Dev

  • Home
  • WordPress
  • WooCommerce

Show LearnDash purchased course details on WooCommerce thank you page

Posted in WooCommerce

Updated on April 6, 2022

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.

Posted on December 20, 2021Tagged add_action, get_items, get_post_meta, get_product_id, get_the_permalink, get_the_title, learndash, woocommerce_after_order_details

Post navigation

Previous PostHide other shipping options in WooCommerce if free shipping is available
Next PostRemove HTML tags from WordPress comments

Recent Posts

  • Make display name not-required on WooCommerce account edit page
  • Limit excerpt length for posts from specific category or taxonomy
  • Don’t redirect to WooCommerce product single page after “add-to-cart” error
  • Add new WooCommerce checkout field
  • Update shipping fee on state and postcode change on WooCommerce checkout page

Friendly Tags

acf add_action admin_head admin_notices advanced custom field billing_postcode checkout fields core_update_footer current_user_can do_shortcode flush_rules free_shipping get_bloginfo get_cart get_current_screen get_field get_the_excerpt has_term init is_in_stock is_main_query is_search is_wp_error learndash manage_options method_id Paid Membership Pro permalink PMPro pre_get_posts remove_filter search shipping_postcode template_redirect the_excerpt update_footer wc_get_page_permalink woocommerce_before_shop_loop_item_title woocommerce_checkout_fields woocommerce_email_order_items_args woocommerce_package_rates woocommerce_thankyou wp_footer wp_head wp_rewrite
©2026 careless.dev All Rights Reserved.
Web Hosting powered by DCT IT.
Privacy Policy | Contact Us