Skip to content

Instantly share code, notes, and snippets.

@imran-khan1
Last active July 12, 2019 12:52
Show Gist options
  • Save imran-khan1/bb91c8f626fb3ae927ee8947e098f47e to your computer and use it in GitHub Desktop.
Save imran-khan1/bb91c8f626fb3ae927ee8947e098f47e to your computer and use it in GitHub Desktop.
<?php
/**
* Insert the new endpoint into the My Account menu.
*
* @param array $items
* @return array
*/
function ci_custom_account_menu_items( $items ) {
// Remove the logout menu item.
$logout = $items['customer-logout'];
unset( $items['customer-logout'] );
// Insert your custom endpoint.
$items['ci-custom-endpoint'] = __( 'CI Custom Endpoint', 'woocommerce' );
// Insert back the logout item.
$items['customer-logout'] = $logout;
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'ci_custom_account_menu_items' );
function flush_rules(){
add_rewrite_endpoint( 'ci-custom-endpoint', EP_ROOT | EP_PAGES );
flush_rewrite_rules();
}
add_action('init','flush_rules');
/**
* Endpoint HTML content.
*/
function ci_custom_endpoint_content() {
echo '<p>Hello World!</p>';
//add below file within theme directory
include get_template_directory().'/my-custom-endpoint.php';
}
add_action( 'woocommerce_account_ci-custom-endpoint_endpoint', 'ci_custom_endpoint_content' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment