Back to Top

WooCommerce My Account Custom Endpoint

Updated 13 March 2024

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
WordPress Company ?
Find out 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! Also, Hire WooCommerce Developers for all kinds of services for web and mobile development, plugin development, mobile app, design services, and much more.

If you need custom WordPress Development services then feel free to reach us and also explore our exclusive range of WordPress WooCommerce Extensions.

Thanks for Your Time! Have a Good Day!

. . .

Leave a Comment

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


6 comments

  • MrCode
  • Alex Paul
  • dcrecm
    • Webkul Support
  • Thakur Amit Chauhan
    • Webkul Support
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home

    Table of Content