array(),\n 'body' => '{"status":"ok"}',\n 'response' => array(\n 'code' => 200,\n 'message' => 'OK',\n ),\n 'cookies' => array(),\n 'filename' => null,\n );\n }\n return $pre;\n}, 10, 3 );\n\n// ─────────────────────────────────────────────\n// 4. БАГАТОМОВНЕ СОРТУВАННЯ КАТАЛОГУ ПОСЛУГ ЗА ПЕРЕГЛЯДАМИ\n// ─────────────────────────────────────────────\nif ( ! function_exists( 'jcp_get_multilingual_term_views' ) ) {\n function jcp_get_multilingual_term_views( $term_id ) {\n $term_id = (int) $term_id;\n $views = get_term_meta( $term_id, 'jc_total_views', true );\n \n if ( $views !== '' && $views !== false && (int) $views > 0 ) {\n return (int) $views;\n }\n \n // Якщо це перекладена категорія (WPML), підтягуємо перегляди з оригінальної української категорії\n global $wpdb;\n $sql_orig = $wpdb->prepare("\n SELECT tt_orig.term_id\n FROM {$wpdb->term_taxonomy} tt_curr\n JOIN {$wpdb->prefix}icl_translations tr_curr ON tr_curr.element_id = tt_curr.term_taxonomy_id AND tr_curr.element_type = 'tax_product_cat'\n JOIN {$wpdb->prefix}icl_translations tr_orig ON tr_orig.trid = tr_curr.trid AND tr_orig.element_type = 'tax_product_cat' AND tr_orig.language_code = 'uk'\n JOIN {$wpdb->term_taxonomy} tt_orig ON tt_orig.term_taxonomy_id = tr_orig.element_id\n WHERE tt_curr.term_id = %d\n LIMIT 1\n ", $term_id);\n \n $orig_id = (int) $wpdb->get_var( $sql_orig );\n if ( $orig_id && $orig_id !== $term_id ) {\n $orig_views = (int) get_term_meta( $orig_id, 'jc_total_views', true );\n if ( $orig_views > 0 ) {\n return $orig_views;\n }\n }\n \n return (int) $views;\n }\n}\n\nif ( ! function_exists( 'jcp_get_multilingual_post_views' ) ) {\n /**\n * Отримує кількість переглядів послуги (товару) з урахуванням багатомовності WPML.\n * Якщо у перекладеної послуги 0 переглядів, підтягує перегляди оригінальної послуги (UK).\n */\n function jcp_get_multilingual_post_views( $post_id ) {\n $post_id = (int) $post_id;\n $views = function_exists( 'pvc_get_post_views' ) ? (int) pvc_get_post_views( $post_id ) : 0;\n \n if ( $views > 0 ) {\n return $views;\n }\n \n // Якщо це перекладений товар (WPML), шукаємо оригінальний український товар\n global $wpdb;\n $sql_orig = $wpdb->prepare("\n SELECT tr_orig.element_id\n FROM {$wpdb->prefix}icl_translations tr_curr\n JOIN {$wpdb->prefix}icl_translations tr_orig ON tr_orig.trid = tr_curr.trid AND tr_orig.element_type = tr_curr.element_type AND tr_orig.language_code = 'uk'\n WHERE tr_curr.element_id = %d AND tr_curr.element_type = 'post_product'\n LIMIT 1\n ", $post_id);\n \n $orig_id = (int) $wpdb->get_var( $sql_orig );\n if ( $orig_id && $orig_id !== $post_id ) {\n $orig_views = function_exists( 'pvc_get_post_views' ) ? (int) pvc_get_post_views( $orig_id ) : 0;\n if ( $orig_views > 0 ) {\n return $orig_views;\n }\n }\n \n return $views;\n }\n}\n\nadd_filter( 'woocommerce_get_product_subcategories', function( $categories, $parent_id ) {\n if ( empty( $categories ) || ! is_array( $categories ) ) {\n return $categories;\n }\n \n usort( $categories, function( $a, $b ) {\n $views_a = jcp_get_multilingual_term_views( $a->term_id );\n $views_b = jcp_get_multilingual_term_views( $b->term_id );\n \n if ( $views_a === $views_b ) {\n return strcmp( $a->name, $b->name );\n }\n return ( $views_a > $views_b ) ? -1 : 1;\n } );\n \n return $categories;\n}, 999, 2 );\n\n\n// END ENQUEUE PARENT ACTION\n// 5. ПІДКЛЮЧЕННЯ СТИЛІВ АДВОКАТІВ (ADVOCAT)\nadd_action( 'wp_enqueue_scripts', function() {\n if ( is_singular( 'advocat' ) || is_post_type_archive( 'advocat' ) || is_tax( 'adv_loc' ) || get_query_var( 'advocat_main' ) || get_query_var( 'advocat_location' ) ) {\n $adv_css = get_stylesheet_directory() . '/advocat/advocat.css';\n $adv_ver = file_exists( $adv_css ) ? filemtime( $adv_css ) : '1.2.0';\n wp_enqueue_style( 'advocat-css', get_stylesheet_directory_uri() . '/advocat/advocat.css', array('jcp-unified-ds'), $adv_ver );\n }\n}, 20 );\n// Підключення шорткодів адвокатів\nrequire_once get_stylesheet_directory() . '/advocat/advocat-shortcodes.php';\nrequire_once get_stylesheet_directory() . '/advocat-api.php';\n// Підключення структури URL адвокатів\nrequire_once get_stylesheet_directory() . '/advocat/advocat-rewrite.php';\nrequire_once get_stylesheet_directory() . '/gov_post/gov-rewrite.php';\n// Підключення стилів для держустанов (GOV)\nadd_action( 'wp_enqueue_scripts', function() {\n if ( is_singular( 'gov' ) || is_post_type_archive( 'gov' ) || is_tax( 'gov_type' ) || is_tax( 'location' ) || get_query_var( 'gov_main' ) ) {\n wp_enqueue_style( 'gov-catalog-css', get_stylesheet_directory_uri() . '/gov_post/gov-catalog.css', array(), '1.1' );\n }\n}, 20 );\n\n\n\n// ─────────────────────────────────────────────\n// 6. ПІДКЛЮЧЕННЯ WOOCOMMERCE SINGLE PRODUCT TWEAKS & WIDGETS\n// ─────────────────────────────────────────────\nrequire_once get_stylesheet_directory() . '/woocommerce-single-product-tweaks.php';\nrequire_once get_stylesheet_directory() . '/jcp-consult-block.php';\nrequire_once get_stylesheet_directory() . '/author-carousel.php';\nrequire_once get_stylesheet_directory() . '/floating-contact-buttons.php';\nrequire_once get_stylesheet_directory() . '/bitrix24-widget.php';\nrequire_once get_stylesheet_directory() . '/theme-footer.php';\n\n// Single product styles now loaded via woocommerce-single-product.css in child theme\n\n\n// ─────────────────────────────────────────────\n// ─────────────────────────────────────────────\n// ─────────────────────────────────────────────\n\n\nrequire_once __DIR__ . '/get-post-by-url.php';\n\n\n\nrequire_once __DIR__ . '/n8n-webhook.php';\nrequire_once __DIR__ . '/cf7-webhook.php';\n\n// ─────────────────────────────────────────────\n// 6. ПІДКЛЮЧЕННЯ СТИЛІВ ДЕРЖАВНИХ УСТАНОВ (GOV)\n// ─────────────────────────────────────────────\nadd_action( 'wp_enqueue_scripts', function() {\n if ( is_singular( 'gov' ) || is_post_type_archive( 'gov' ) || is_tax( 'gov_type' ) || is_tax( 'location' ) || is_tax( 'gov_structure' ) || get_query_var( 'gov_main' ) || get_query_var( 'gov_tax_slug' ) || get_query_var( 'gov_tax_child' ) || ( isset( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], '/gov' ) !== false ) ) {\n wp_enqueue_style( 'gov-catalog-css', get_stylesheet_directory_uri() . '/gov_post/gov-catalog.css', array(), '1.0.5' );\n wp_enqueue_style( 'gov-catalog-root-css', get_stylesheet_directory_uri() . '/gov-catalog.css', array(), '1.0.5' );\n }\n}, 20 );\n\n// ─────────────────────────────────────────────\n// 7. АВТОМАТИЧНЕ ДОДАВАННЯ КЛАСІВ body.gov-page ТА body.advocat-page\n// ─────────────────────────────────────────────\nadd_filter( 'body_class', function( $classes ) {\n if ( is_singular( 'gov' ) || is_post_type_archive( 'gov' ) || is_tax( 'location' ) || is_tax( 'gov_type' ) || is_tax( 'gov_structure' ) || get_query_var( 'gov_main' ) || get_query_var( 'gov_tax_slug' ) || get_query_var( 'gov_tax_child' ) || ( isset( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], '/gov' ) !== false ) ) {\n if ( ! in_array( 'gov-page', $classes ) ) {\n $classes[] = 'gov-page';\n }\n }\n if ( is_singular( 'advocat' ) || is_post_type_archive( 'advocat' ) || is_tax( 'adv_loc' ) || get_query_var( 'advocat_main' ) || get_query_var( 'advocat_location' ) || ( isset( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], '/advocat' ) !== false ) ) {\n if ( ! in_array( 'advocat-page', $classes ) ) {\n $classes[] = 'advocat-page';\n }\n }\n return $classes;\n} );\n\n// ─────────────────────────────────────────────\n// 8. ДИНАМІЧНИЙ ВИВІД КАРТКИ PDF-ДОКУМЕНТА (ВІДЮРКОНСАЛТ)\n// ─────────────────────────────────────────────\nadd_filter( 'the_content', 'jc_insert_pdf_document_block', 14 );\n\nfunction jc_insert_pdf_document_block( $content ) {\n if ( is_singular( 'post' ) || is_singular( 'victory_case' ) || is_singular( 'product' ) ) {\n $post_id = get_the_ID();\n \n // WPML підтримка\n if ( has_filter( 'wpml_original_element_id' ) ) {\n $original_id = apply_filters( 'wpml_original_element_id', NULL, $post_id, 'post_' . get_post_type( $post_id ) );\n if ( $original_id ) { $post_id = $original_id; }\n }\n \n $pdf_url = get_post_meta( $post_id, 'jc_pdf_document_url', true );\n $pdf_title = get_post_meta( $post_id, 'jc_pdf_document_title', true );\n \n if ( ! empty( $pdf_url ) ) {\n $default_pdf_title = (defined("ICL_LANGUAGE_CODE") && ICL_LANGUAGE_CODE == 'ru') ? 'Скачать официальный образец документа' : 'Завантажити офіційний зразок документа';\n if ( empty( $pdf_title ) ) {\n $pdf_title = $default_pdf_title;\n }\n \n $doc_label = (defined("ICL_LANGUAGE_CODE") && ICL_LANGUAGE_CODE == 'ru') ? '📄 Образец документа' : '📄 Зразок документа';\n $btn_label = (defined("ICL_LANGUAGE_CODE") && ICL_LANGUAGE_CODE == 'ru') ? '👁 Смотреть / Скачать PDF' : '👁 Переглянути / Завантажити PDF';\n \n $pdf_html = '\n