diff --git a/CLAUDE.md b/CLAUDE.md index 9d1a57d..44a8718 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -553,3 +553,18 @@ Full API documentation available in `openapi.json` (OpenAPI 3.1 specification). - Domain validation with normalization (strips protocol, www prefix) - Inline edit UI with save/cancel for license domains - Links to full licenses management page for advanced actions + +**Bug fix (post v0.0.10):** + +- Fixed: Licenses menu item in customer account page resulted in 404 error + +**Root cause:** + +- WooCommerce My Account endpoints require both `add_rewrite_endpoint()` AND registration with `woocommerce_get_query_vars` filter +- The endpoint also needs to be registered before rewrite rules are flushed during activation + +**Fix:** + +- Added `addLicensesQueryVar()` method to register the endpoint query var with WooCommerce +- Updated Installer to register endpoint before flushing rewrite rules on activation +- Existing installations may need to visit Settings > Permalinks and click Save to regenerate rewrite rules diff --git a/src/Frontend/AccountController.php b/src/Frontend/AccountController.php index e9ccebc..1a9af4f 100644 --- a/src/Frontend/AccountController.php +++ b/src/Frontend/AccountController.php @@ -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 */ diff --git a/src/Installer.php b/src/Installer.php index e07807f..ee7ff80 100644 --- a/src/Installer.php +++ b/src/Installer.php @@ -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(); }