/** * ============================================= * TAB 1: MISMA MARCA * ============================================= */ add_filter( 'woocommerce_product_tabs', 'woo_same_brand_products_tab' ); function woo_same_brand_products_tab( $tabs ) { global $product; $brands = wp_get_post_terms( $product->get_id(), 'pwb-brand' ); if ( ! empty( $brands ) && ! is_wp_error( $brands ) ) { $brand = $brands[0]; $same_brand_products = get_posts(array( 'post_type' => 'product', 'posts_per_page' => -1, 'post__not_in' => array( $product->get_id() ), 'tax_query' => array(array( 'taxonomy' => 'pwb-brand', 'field' => 'term_id', 'terms' => $brand->term_id, )), )); if ( count( $same_brand_products ) > 0 ) { $tabs['same_brand_tab'] = array( 'title' => __( 'Más de ' . $brand->name, 'woocommerce' ), 'priority' => 50, 'callback' => 'woo_same_brand_products_content' ); } } return $tabs; } function woo_same_brand_products_content() { global $product; $brands = wp_get_post_terms( $product->get_id(), 'pwb-brand' ); if ( ! empty( $brands ) && ! is_wp_error( $brands ) ) { $brand = $brands[0]; $brand_link = get_term_link( $brand ); $same_brand_products = new WP_Query(array( 'post_type' => 'product', 'posts_per_page' => 10, 'post__not_in' => array( $product->get_id() ), 'tax_query' => array(array( 'taxonomy' => 'pwb-brand', 'field' => 'term_id', 'terms' => $brand->term_id, )), 'meta_key' => '_stock_status', 'meta_value' => 'instock', )); if ( $same_brand_products->have_posts() ) { echo '

Más productos de la marca ' . esc_html( $brand->name ) . '

'; woocommerce_product_loop_start(); while ( $same_brand_products->have_posts() ) { $same_brand_products->the_post(); wc_get_template_part( 'content', 'product' ); } woocommerce_product_loop_end(); echo '
Ver todos los productos de ' . esc_html( $brand->name ) . '
'; } wp_reset_postdata(); } } /** * ============================================= * TAB 2: PRODUCTOS SIMILARES (VERSIÓN MEJORADA - MISMA CATEGORÍA ESPECÍFICA) * ============================================= */ add_filter( 'woocommerce_product_tabs', 'woo_similar_products_tab', 20 ); function woo_similar_products_tab( $tabs ) { global $product; // Obtener la categoría más específica del producto $target_category = woo_get_most_specific_category( $product->get_id() ); if ( $target_category ) { // Verificar si hay otros productos en esa misma categoría $similar_products = get_posts(array( 'post_type' => 'product', 'posts_per_page' => -1, 'post__not_in' => array( $product->get_id() ), 'tax_query' => array(array( 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $target_category->term_id, 'include_children' => true, )), )); if ( count( $similar_products ) > 0 ) { $tabs['similar_products_tab'] = array( 'title' => __( 'Productos Similares', 'woocommerce' ), 'priority' => 51, 'callback' => 'woo_similar_products_tab_content' ); } } return $tabs; } function woo_similar_products_tab_content() { global $product; // Obtener la categoría más específica del producto $target_category = woo_get_most_specific_category( $product->get_id() ); if ( $target_category ) { $similar_products = new WP_Query(array( 'post_type' => 'product', 'posts_per_page' => 10, 'post__not_in' => array( $product->get_id() ), 'tax_query' => array(array( 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $target_category->term_id, 'include_children' => true, )), 'meta_key' => '_stock_status', 'meta_value' => 'instock', 'orderby' => 'rand', )); if ( $similar_products->have_posts() ) { echo '

Productos Similares

'; echo '

Descubre otros productos de la misma categoría que podrían interesarte:

'; woocommerce_product_loop_start(); while ( $similar_products->have_posts() ) { $similar_products->the_post(); wc_get_template_part( 'content', 'product' ); } woocommerce_product_loop_end(); // Botón para ver todos los productos de esa categoría (opcional) echo '
'; echo 'Ver todos los productos de ' . esc_html( $target_category->name ) . ''; echo '
'; } else { echo '

No se encontraron productos similares en esta categoría.

'; } wp_reset_postdata(); } else { echo '

Este producto no tiene categorías asignadas.

'; } } /** * Función auxiliar: Obtiene la categoría más específica del producto * Ej: Si el producto está en "KSA > Ordenadores > Portátiles", devuelve "Portátiles" */ function woo_get_most_specific_category( $product_id ) { $categories = wp_get_post_terms( $product_id, 'product_cat' ); if ( empty( $categories ) || is_wp_error( $categories ) ) { return null; } // Buscar la categoría que NO es padre de ninguna otra foreach ( $categories as $possible_category ) { $is_parent = false; foreach ( $categories as $compare_category ) { if ( $compare_category->term_id !== $possible_category->term_id && term_is_ancestor_of( $possible_category->term_id, $compare_category->term_id, 'product_cat' ) ) { $is_parent = true; break; } } if ( ! $is_parent ) { return $possible_category; } } // Si no encuentra, devuelve la primera categoría como respaldo return $categories[0]; } /** * TAB: NUEVOS PRODUCTOS (Novedad) */ add_filter( 'woocommerce_product_tabs', 'woo_new_arrivals_tab', 43 ); function woo_new_arrivals_tab( $tabs ) { $tabs['new_arrivals_tab'] = array( 'title' => __( 'Recién Llegados', 'woocommerce' ), 'priority' => 63, 'callback' => 'woo_new_arrivals_tab_content' ); return $tabs; } function woo_new_arrivals_tab_content() { $new_arrivals = new WP_Query(array( 'post_type' => 'product', 'posts_per_page' => 10, 'orderby' => 'date', 'order' => 'DESC', 'meta_key' => '_stock_status', 'meta_value' => 'instock', )); if ( $new_arrivals->have_posts() ) { echo '

🆕 Lo último en nuestra tienda

'; echo '

Descubre las novedades antes que nadie:

'; woocommerce_product_loop_start(); while ( $new_arrivals->have_posts() ) { $new_arrivals->the_post(); wc_get_template_part( 'content', 'product' ); } woocommerce_product_loop_end(); wp_reset_postdata(); } } /** * TAB: PRODUCTOS EN OFERTA (Urgencia) */ add_filter( 'woocommerce_product_tabs', 'woo_sale_products_tab', 41 ); function woo_sale_products_tab( $tabs ) { $tabs['sale_products_tab'] = array( 'title' => __( 'Ofertas Especiales', 'woocommerce' ), 'priority' => 61, 'callback' => 'woo_sale_products_tab_content' ); return $tabs; } function woo_sale_products_tab_content() { $sale_products = new WP_Query(array( 'post_type' => 'product', 'posts_per_page' => 10, 'post__in' => wc_get_product_ids_on_sale(), 'meta_key' => '_stock_status', 'meta_value' => 'instock', 'orderby' => 'rand', )); if ( $sale_products->have_posts() ) { echo '

Ahorra con nuestras ofertas

'; echo '

Precios especiales por tiempo limitado:

'; woocommerce_product_loop_start(); while ( $sale_products->have_posts() ) { $sale_products->the_post(); wc_get_template_part( 'content', 'product' ); } woocommerce_product_loop_end(); wp_reset_postdata(); } else { echo '

No hay ofertas activas en este momento. ¡Vuelve pronto!

'; } } GENERICA – clicktechonline https://clicktechonline.com Tienda material de informatica electronica ordenadores portatiles Thu, 16 Apr 2026 07:06:59 +0000 es hourly 1 https://clicktechonline.com/wp-content/uploads/2024/03/cropped-favikon-32x32.png GENERICA – clicktechonline https://clicktechonline.com 32 32