Fix licenses endpoint 404 error in customer account

- Register licenses query var with WooCommerce via woocommerce_get_query_vars
- Register endpoint in Installer before flushing rewrite rules
- Existing installations need to re-save permalinks

The endpoint was not being recognized because WooCommerce's My Account
requires both add_rewrite_endpoint() and query var registration.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-21 22:24:43 +01:00
parent f22ae95d6e
commit 0e554d4139
3 changed files with 31 additions and 1 deletions

View File

@@ -44,6 +44,9 @@ final class AccountController
// Add licenses endpoint
add_action('init', [$this, 'addLicensesEndpoint']);
// Register endpoint query var with WooCommerce
add_filter('woocommerce_get_query_vars', [$this, 'addLicensesQueryVar']);
// Add licenses menu item
add_filter('woocommerce_account_menu_items', [$this, 'addLicensesMenuItem']);
@@ -65,6 +68,15 @@ final class AccountController
add_rewrite_endpoint('licenses', EP_ROOT | EP_PAGES);
}
/**
* Register licenses query var with WooCommerce
*/
public function addLicensesQueryVar(array $vars): array
{
$vars['licenses'] = 'licenses';
return $vars;
}
/**
* Add licenses menu item to My Account navigation
*/

View File

@@ -35,7 +35,10 @@ final class Installer
// Set version in options
update_option('wc_licensed_product_version', WC_LICENSED_PRODUCT_VERSION);
// Flush rewrite rules for REST API
// Register the licenses endpoint before flushing rewrite rules
add_rewrite_endpoint('licenses', EP_ROOT | EP_PAGES);
// Flush rewrite rules for REST API and My Account endpoints
flush_rewrite_rules();
}