/* ============================================================
 * SPLIT DE DESCRIPCIÓN DE CATEGORÍA — El Herbolario Online
 *
 * Divide la descripción de categoría WooCommerce en dos partes
 * usando el separador <!--split-->:
 *   - Parte 1 (INTRO): se muestra ENCIMA de los productos
 *   - Parte 2 (CONTENT): se muestra DEBAJO de los productos
 *
 * Uso: en el campo Descripción de cada categoría WooCommerce,
 * escribe el texto introductorio, luego <!--split-->, luego
 * el texto largo con H2, negritas y tabla técnica.
 * ============================================================ */

/**
 * Obtiene las dos partes de la descripción de categoría.
 * Devuelve ['intro' => '...', 'content' => '...']
 * Si no hay separador, intro = descripción completa, content = ''.
 */
function eho_get_category_description_parts() {
    static $cache = [];

    if ( ! is_tax( 'product_cat' ) ) return [ 'intro' => '', 'content' => '' ];

    $term = get_queried_object();
    if ( ! $term || ! isset( $term->term_id ) ) return [ 'intro' => '', 'content' => '' ];

    $id = $term->term_id;
    if ( isset( $cache[ $id ] ) ) return $cache[ $id ];

    $desc = term_description( $id, 'product_cat' );

    if ( strpos( $desc, '<!--split-->' ) !== false ) {
        $parts   = explode( '<!--split-->', $desc, 2 );
        $result  = [
            'intro'   => wp_kses_post( trim( $parts[0] ) ),
            'content' => wp_kses_post( trim( $parts[1] ) ),
        ];
    } else {
        $result = [ 'intro' => wp_kses_post( trim( $desc ) ), 'content' => '' ];
    }

    $cache[ $id ] = $result;
    return $result;
}

/**
 * PARTE 1 — Mostrar el INTRO encima de los productos.
 * Se engancha en woocommerce_before_shop_loop (antes del grid de productos).
 */
add_action( 'woocommerce_before_shop_loop', 'eho_category_intro_above_products', 5 );
function eho_category_intro_above_products() {
    if ( ! is_tax( 'product_cat' ) ) return;

    $parts = eho_get_category_description_parts();
    if ( empty( $parts['intro'] ) ) return;

    echo '<div class="eho-category-intro" style="margin-bottom:24px;">';
    echo $parts['intro'];
    echo '</div>';
}

/**
 * PARTE 2 — Mostrar el CONTENT debajo de los productos.
 * Se engancha en woocommerce_after_shop_loop (después del grid de productos).
 */
add_action( 'woocommerce_after_shop_loop', 'eho_category_content_below_products', 20 );
function eho_category_content_below_products() {
    if ( ! is_tax( 'product_cat' ) ) return;

    $parts = eho_get_category_description_parts();
    if ( empty( $parts['content'] ) ) return;

    echo '<div class="eho-category-content" style="margin-top:40px;padding-top:32px;border-top:1px solid #e8e8e8;">';
    echo $parts['content'];
    echo '</div>';
}

/**
 * Eliminar la descripción de categoría que WooCommerce muestra
 * por defecto (encima de los productos), para evitar duplicados.
 * Nuestras funciones anteriores ya gestionan dónde se muestra cada parte.
 */
remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//elherbolarioonline.es/wp-content/plugins/wordpress-seo/css/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://elherbolarioonline.es/post-sitemap.xml</loc>
		<lastmod>2026-04-07T08:42:06+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://elherbolarioonline.es/page-sitemap.xml</loc>
		<lastmod>2026-04-13T12:50:52+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://elherbolarioonline.es/product-sitemap.xml</loc>
		<lastmod>2026-04-13T12:56:22+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://elherbolarioonline.es/product-sitemap2.xml</loc>
		<lastmod>2026-04-13T10:54:43+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://elherbolarioonline.es/product-sitemap3.xml</loc>
		<lastmod>2026-04-13T12:26:24+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://elherbolarioonline.es/product-sitemap4.xml</loc>
		<lastmod>2026-04-13T12:27:18+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://elherbolarioonline.es/product-sitemap5.xml</loc>
		<lastmod>2026-04-13T12:27:56+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://elherbolarioonline.es/product-sitemap6.xml</loc>
		<lastmod>2026-04-13T12:28:59+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://elherbolarioonline.es/product-sitemap7.xml</loc>
		<lastmod>2026-04-13T12:54:47+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://elherbolarioonline.es/product-sitemap8.xml</loc>
		<lastmod>2026-04-13T12:55:29+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://elherbolarioonline.es/product-sitemap9.xml</loc>
		<lastmod>2026-04-13T12:56:22+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://elherbolarioonline.es/category-sitemap.xml</loc>
		<lastmod>2026-04-07T08:42:06+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://elherbolarioonline.es/product_brand-sitemap.xml</loc>
		<lastmod>2026-04-13T12:56:22+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://elherbolarioonline.es/product_cat-sitemap.xml</loc>
		<lastmod>2026-04-13T12:56:22+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://elherbolarioonline.es/product_tag-sitemap.xml</loc>
		<lastmod>2026-04-13T12:56:22+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://elherbolarioonline.es/author-sitemap.xml</loc>
		<lastmod>2026-03-26T08:03:14+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Yoast SEO -->