Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Daniel217D/349be32951a6549c63e76634b7d9ebca to your computer and use it in GitHub Desktop.
Save Daniel217D/349be32951a6549c63e76634b7d9ebca to your computer and use it in GitHub Desktop.
woocommerce - get active account menu item
function get_active_account_menu_item() {
global $wp;
$items = wc_get_account_menu_items();
$current = false;
foreach ($items as $endpoint => $label) {
// Set current item class.
$current = isset( $wp->query_vars[ $endpoint ] );
if ( 'dashboard' === $endpoint && ( isset( $wp->query_vars['page'] ) || empty( $wp->query_vars ) ) ) {
$current = true; // Dashboard is not an endpoint, so needs a custom check.
}
if($current) {
$current = $endpoint;
break;
}
}
return $current;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment