feat: implement WooCommerce AJAX product search

This commit is contained in:
XShop
2026-09-13 20:01:15 +03:30
parent 00439fcea9
commit f5c283af25
14 changed files with 760 additions and 37 deletions
+8
View File
@@ -23,6 +23,14 @@ function xshop_enqueue_assets(): void {
// Theme JS is tiny; feature modules conditionally enqueued elsewhere.
wp_enqueue_script('xshop', XSHOP_THEME_URI . '/assets/js/theme.js', [], $ver, true);
// Search JS — only where ajax-search component is rendered (header has it globally, so enqueue on front-end when search UI exists)
// We check for header search presence via has_action or simply enqueue on all front-end where header is rendered (is not admin/customizer preview irrelevant)
// To satisfy "only where useful" while keeping header simple, enqueue on non-admin front-end (header renders on all front-end pages)
if (!is_admin() && !wp_is_json_request()) {
// Only enqueue if theme header will render (which is all front-end). We further guard via DOM marker in JS (init guard).
wp_enqueue_script('xshop-search', XSHOP_THEME_URI . '/assets/js/search.js', [], $ver, true);
}
// Localized data for REST/AJAX (nonces, i18n hints).
wp_localize_script('xshop', 'xshopData', [
'restUrl' => esc_url_raw(rest_url('xshop/v1/')),