• Resolved mewillian

    (@mewillian)


    Hello, I have a site that sells individual courses.

    Is there a way i can do a page that shows the user the list of courses he bought? Similar to ‘my orders’ endpoint but i want some sort of list of images with each image sending the user to a specified URL.

    Like this:

    • This topic was modified 1 year, 7 months ago by mewillian.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @mewillian

    To show the list of purchased products after logging in, you can use a custom code snippet. Simply add the following code to your theme’s functions.php file:

    add_shortcode( 'my_purchased_products', 'srdev_products_bought_by_curr_user' );
       
    function srdev_products_bought_by_curr_user() {
       
        // GET CURR USER
        $current_user = wp_get_current_user();
        if ( 0 == $current_user->ID ) return;
       
        // GET USER ORDERS (COMPLETED + PROCESSING)
        $customer_orders = get_posts( array(
            'numberposts' => -1,
            'meta_key'    => '_customer_user',
            'meta_value'  => $current_user->ID,
            'post_type'   => wc_get_order_types(),
            'post_status' => array_keys( wc_get_is_paid_statuses() ),
        ) );
       
        // LOOP THROUGH ORDERS AND GET PRODUCT IDS
        if ( ! $customer_orders ) return;
        $product_ids = array();
        foreach ( $customer_orders as $customer_order ) {
            $order = wc_get_order( $customer_order->ID );
            $items = $order->get_items();
            foreach ( $items as $item ) {
                $product_id = $item->get_product_id();
                $product_ids[] = $product_id;
            }
        }
        $product_ids = array_unique( $product_ids );
        $product_ids_str = implode( ",", $product_ids );
       
        // PASS PRODUCT IDS TO PRODUCTS SHORTCODE
        return do_shortcode("[products ids='$product_ids_str']");
       
    }

    Now create a page and add the shortcode [my_purchased_products]. Once your customer logs in and accesses this page, they’ll be able to see a list of all the products they’ve purchased. It’s as simple as that!

    If you want to add this page to your account menu, just follow this detailed guide: https://woocommerce.com/document/customize-my-account-for-woocommerce/#section-7. It’s super easy to follow and will have you customizing your account in no time.

    Hi @mewillian

    Thanks for reaching out!

    I understand that you would like to create a separate page for the list of purchased courses of your customers on your site similar to the Orders endpoint, correct?

    As a first step, can you please share how courses are added to your site as this is not part of the core functions of WooCommerce?

    If this was added thru a third-party plugin or a custom code, it would be best to reach out to the developers for further assistance here.

    Furthermore, this is a bit of a complicated topic that would need some customization to address. Unfortunately, custom coding is not something we can assist with directly. However, I’ll keep this thread open for a bit to see if anyone from the community can lend a hand.

    If you have any other questions related to development or custom coding, don’t hesitate to reach out to some of the great resources we have available for support. The WooCommerce community is filled with talented open-source developers, and many of them are active on the channels listed below:

    Hope this helps!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Page showing list of bought products’ is closed to new replies.