Read More
Menu Close

    WooCommerce My Account Custom Endpoint

    WooCommerce Account Page Custom Endpoint – In this post, we will see how we can add custom endpoint to my account page in front means one new our own page like order, download (default one’s).

    To do this, first we’ll add rewrite endpoint using WordPress function ‘add_rewrite_endpoint’ on ‘init’ hook.

    <?php
    
    /**
    *   Plugin Name: WooCommerce Custom Endpoint Webkul
    *   Description: An example plugin to add custom endpoint to My Account Page.
    *   Author: Webkul
    *   Author URI: https://webkul.com
    *   Plugin URI: https://webkul.com
    *   Text Domain: webkul
    */
    
    
    function wk_custom_endpoint() {
      add_rewrite_endpoint( 'custom', EP_ROOT | EP_PAGES );
    }
    
    add_action( 'init', 'wk_custom_endpoint' );
    
    ?>

    In add_rewrite_endpoint function first parameter is name of endpoint and second is places where endpoint will add. We add endpoint to root and pages. The endpoint name is added as query variable. You can explore more places and about this function using below link –

    Reference – https://codex.wordpress.org/Rewrite_API/add_rewrite_endpoint.

    Now, we will add menu item for this custom endpoint on WooCommerce My Account page menu so that we can access easily. For this we’ll use ‘woocommerce_account_menu_items’ filter.

    Searching for an experienced
    Woocommerce Company ?
    Read More
    add_filter( 'woocommerce_account_menu_items', 'wk_new_menu_items' );
    
    /**
    * Insert the new endpoint into the My Account menu.
    *
    * @param array $items
    * @return array
    */
    function wk_new_menu_items( $items ) {
    	$items[ 'custom' ] = __( 'Custom', 'webkul' );
    	return $items;
    }
    

    The above code will add one more menu item named Custom at the end of my account page menu list.

    The endpoint has been added, menu item also added, now next thing will be, how can we add content to this new (say) page..? Not to worry, WooCommerce provide the hook using which we can add content –

    $endpoint = 'custom';
    
    add_action( 'woocommerce_account_' . $endpoint .  '_endpoint', 'wk_endpoint_content' );
    
    function wk_endpoint_content() {
        //content goes here
        echo '//content goes here';    
    }
    

    Support

    Still have any issue feel free to add a ticket and let us know your views to make the code better https://webkul.uvdesk.com/en/customer/create-ticket/

    Thanks for Your Time! Have a Good Day!

    . . .
    Discuss on Helpdesk

    Leave a Comment

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


    4 comments

  • dcrecm
    Hello thanks for this tutorial, can you give me another information, how to make it also appear in configuration -> account – this endpoint in woocommerce?

    And about the content, I wanted to make there appear the content of courses bought by the sensei plugin, could it be possible to add a page to show?

    • Webkul Support
      Hello, you’re welcome. For your first point we will write one more post regarding that and second about the content at added endpoint in front-end, the action hook ‘woocommerce_account_’ . $endpoint . ‘_endpoint’ described in last code snippet in this blog will be used.
  • Thakur Amit Chauhan
    Great articles looking forward for some more useful info in near future much applauded
    • Webkul Support
      Thank You
  • Back to Top

    Table of Content