Problem: Frontend taxonomy pages (Categories, Tags, Attributes) were getting 404 errors
when trying to create/update/delete because the backend endpoints didn't exist.
Solution: Added complete CRUD API endpoints to ProductsController
Routes Added:
1. Categories:
- POST /products/categories (create)
- PUT /products/categories/{id} (update)
- DELETE /products/categories/{id} (delete)
2. Tags:
- POST /products/tags (create)
- PUT /products/tags/{id} (update)
- DELETE /products/tags/{id} (delete)
3. Attributes:
- POST /products/attributes (create)
- PUT /products/attributes/{id} (update)
- DELETE /products/attributes/{id} (delete)
Implementation:
- All endpoints use admin permission check
- Proper sanitization of inputs
- WordPress taxonomy functions (wp_insert_term, wp_update_term, wp_delete_term)
- WooCommerce attribute functions (wc_create_attribute, wc_update_attribute, wc_delete_attribute)
- Error handling with WP_Error checks
- Consistent response format with success/data/message
Methods Added:
- create_category() / update_category() / delete_category()
- create_tag() / update_tag() / delete_tag()
- create_attribute() / update_attribute() / delete_attribute()
Files Modified:
- includes/Api/ProductsController.php (added 9 CRUD methods + route registrations)
Result:
✅ Categories can now be created/edited/deleted from admin SPA
✅ Tags can now be created/edited/deleted from admin SPA
✅ Attributes can now be created/edited/deleted from admin SPA
✅ No more 404 errors on taxonomy operations
29 KiB
29 KiB