WooCommerce MyAccount custom endpoint

I was trying to add a tab in WooCommerce my account page to show enrolled courses directly there from the Learning Management System. I’ve referred this WooCommerce guide. Following is the code I’ve used, I’ve commented in the code block, so each function is self explanatory. The LMS plugin I’ve used here is LearnDash LMS. What we basically trying to do here is adding¬† a WooCommerce MyAccount custom endpoint.

Steps adding WooCommerce MyAccount custom endpoint

Please note following things while doing your custom endpoint. There are three steps.

  1. Create an endpoint and register it (use¬†add_rewrite_endpoint for this). I’ve re-saved permalink settings for getting it activated.
  2. Add new item to the menu (here I’ve used another function to insert the item after finding one, that is ‘a’. ‘b’ function inserts the end point.)
  3. Finally insert the content for that endpoint. (woocommerce_account_{endpoint}_endpoint is the hook to catch the bugger!!. In the above example, woocommerce_account_enrolled-courses_endpoint is the one.)

Third part can be skipped and use a page/post published already. But don’t forget set that page’s parent as “My Account”, otherwise there will be a 404. For example, set example.com/my-account/custom-end-point/

This is how it looked after adding the end point.

WooCommerce MyAccount custom endpoint

As the content, I’ve used the LearnDash’s shortcode for listing profile and courses. Don’t forget to use do_shortcode if you are adding shortcodes in PHP.

Leave a Reply

Your email address will not be published. Required fields are marked *