Skip to content

Instantly share code, notes, and snippets.

@yanknudtskov
Created May 21, 2020 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yanknudtskov/30f023152a0b6d94f7dfb01f92f37580 to your computer and use it in GitHub Desktop.
Save yanknudtskov/30f023152a0b6d94f7dfb01f92f37580 to your computer and use it in GitHub Desktop.
Adding Custom WooCommerce MyAccount Endpoints
<?php
// Add the endpoints
add_action( 'init', 'yanco_add_my_account_endpoints' );
function yanco_add_my_account_endpoints() {
add_rewrite_endpoint( 'my-custom-endpoint', EP_ROOT | EP_PAGES );
add_rewrite_endpoint( 'my-custom-endpoint-2', EP_ROOT | EP_PAGES );
}
// Make custom endpoints available to query vars
add_filter('woocommerce_get_query_vars', 'yanco_woocommerce_get_query_vars' );
function yanco_woocommerce_get_query_vars( $vars ) {
$custom_endpoints = array(
'my-custom-endpoint',
'my-custom-endpoint-2',
);
foreach ( $custom_endpoints as $custom_endpoint ) {
$vars[$custom_endpoint] = $custom_endpoint;
}
return $vars;
};
// Add content to endpoint
add_action( 'woocommerce_account_my-custom-endpoint_endpoint', 'yanco_endpoint_my_custom_endpoint_content' );
function yanco_endpoint_my_custom_endpoint_content() {
echo '<h2>Custom End Point #1</h2>';
}
add_action( 'woocommerce_account_my-custom-endpoint-2_endpoint', 'yanco_endpoint_my_custom_endpoint_2_content' );
function yanco_endpoint_my_custom_endpoint_2_content() {
echo '<h2>Custom End Point #2</h2>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment