array( $this, 'render_search_widget' ) ) ); } public function register_block_category( $categories ) { return array_merge( array( array( 'slug' => 'ymmhero-search', 'title' => __( 'YMM Hero', 'ymm-hero' ), ), ), $categories ); } public function render_search_widget( $atts ) { $this->enqueue_public_assets(); $atts = is_array( $atts ) ? $atts : array(); $general = YMMHERO_Settings::get_general(); $title = ! empty( $atts['title'] ) ? sanitize_text_field( $atts['title'] ) : $general['widget_title']; $button_label = ! empty( $atts['buttonLabel'] ) ? sanitize_text_field( $atts['buttonLabel'] ) : $general['search_button_label']; $year_placeholder = $general['year_placeholder']; $make_placeholder = $general['make_placeholder']; $model_placeholder = $general['model_placeholder']; $years = YMMHERO_DB::get_all_years(); $border_class = 'ymm-border-' . YMMHERO_Settings::get_styling( 'border_style' ); ob_start(); include YMMHERO_PLUGIN_DIR . 'public/views/search-widget.php'; return ob_get_clean(); } public function render_fitment_widget( $atts ) { $this->enqueue_public_assets(); $product_id = is_product() ? get_the_ID() : 0; $mapped_vehicles = $product_id ? array_filter( (array) get_post_meta( $product_id, '_ymmhero_compatible_vehicles', true ) ) : array(); $has_fitment_data = ! empty( $mapped_vehicles ); $years = $has_fitment_data ? YMMHERO_DB::get_all_years() : array(); $fitment_vehicles = array(); if ( $has_fitment_data ) { foreach ( YMMHERO_DB::get_vehicles_by_ids( $mapped_vehicles ) as $vehicle ) { $fitment_vehicles[] = apply_filters( 'ymmhero_fitment_vehicle_data', array( 'year' => (string) $vehicle['year'], 'make' => $vehicle['make'], 'model' => $vehicle['model'], 'id' => (int) $vehicle['id'], ), $vehicle ); } } $general = YMMHERO_Settings::get_general(); $year_placeholder = $general['year_placeholder']; $make_placeholder = $general['make_placeholder']; $model_placeholder = $general['model_placeholder']; $border_class = 'ymm-border-' . YMMHERO_Settings::get_styling( 'border_style' ); ob_start(); include YMMHERO_PLUGIN_DIR . 'public/views/fitment-widget.php'; return ob_get_clean(); } public function render_compatibility_table( $atts ) { $product_id = is_product() ? get_the_ID() : 0; $vehicle_ids = $product_id ? array_filter( (array) get_post_meta( $product_id, '_ymmhero_compatible_vehicles', true ) ) : array(); if ( empty( $vehicle_ids ) ) { return ''; } $vehicles = YMMHERO_DB::get_vehicles_by_ids( $vehicle_ids ); if ( empty( $vehicles ) ) { return ''; } $this->enqueue_public_assets(); ob_start(); include YMMHERO_PLUGIN_DIR . 'public/views/compatibility-table.php'; return ob_get_clean(); } private function enqueue_public_assets() { list( $css_url, $css_ver ) = YMMHERO_Public::asset_url( 'public/assets/ymm-public.css' ); list( $js_url, $js_ver ) = YMMHERO_Public::asset_url( 'public/assets/ymm-public.js' ); wp_enqueue_style( 'ymmhero-public', $css_url, array(), $css_ver ); if ( is_rtl() ) { list( $rtl_url, $rtl_ver ) = YMMHERO_Public::asset_url( 'public/assets/rtl.css' ); wp_enqueue_style( 'ymmhero-public-rtl', $rtl_url, array( 'ymmhero-public' ), $rtl_ver ); } wp_enqueue_script( 'ymmhero-public', $js_url, array( 'jquery' ), $js_ver, true ); YMMHERO_Public::add_inline_styles(); if ( wp_scripts()->get_data( 'ymmhero-public', 'data' ) ) { return; } $general = YMMHERO_Settings::get_general(); wp_localize_script( 'ymmhero-public', 'ymmhero_ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'ymmhero_nonce' ), 'tree' => YMMHERO_DB::get_ymmhero_tree(), 'make_placeholder' => $general['make_placeholder'], 'model_placeholder' => $general['model_placeholder'], 'loading_text' => __( 'Loading…', 'ymm-hero' ), 'error_text' => __( 'Could not load options. Please try again.', 'ymm-hero' ), 'shop_url' => function_exists( 'wc_get_page_permalink' ) ? wc_get_page_permalink( 'shop' ) : home_url( '/' ), 'product_id' => is_product() ? get_the_ID() : 0, /* translators: 1: current page number, 2: total number of pages */ 'page_of_text' => __( 'Page %1$d of %2$d', 'ymm-hero' ), ) ); } public function add_compatibility_tab( $tabs ) { if ( ! YMMHERO_Settings::get_display( 'compatibility_tab_auto_inject' ) ) { return $tabs; } $product_id = get_the_ID(); $vehicle_ids = $product_id ? array_filter( (array) get_post_meta( $product_id, '_ymmhero_compatible_vehicles', true ) ) : array(); if ( empty( $vehicle_ids ) ) { return $tabs; } $tabs['ymmhero_compatibility'] = array( 'title' => __( 'Compatibility', 'ymm-hero' ), 'priority' => 25, 'callback' => array( $this, 'render_compatibility_tab' ), ); return $tabs; } public function render_compatibility_tab() { echo do_shortcode( '[ymmhero_compatibility_table]' ); } }