/*
Theme Name: Hijo
Author: Diego TObar
Description: El hijo de hello elementor
Version: 1.0
Template: hello-elementor

This is the child theme for Hello Elementor theme, generated with Generate Child Theme plugin by catchthemes.

(optional values you can add: Theme URI, Author URI, License, License URI, Tags, Text Domain)
*/

add_filter( 'woocommerce_email_recipient_new_order', 'enviar_notificacion_por_categoria', 10, 2 );

function enviar_notificacion_por_categoria( $recipient, $order ) {
    if ( ! $order ) return $recipient;

    // CONFIGURACIÓN: 'slug-de-la-categoria' => 'correo@destino.com'
    $categorias_y_correos = array(
        'boletos' => 'produccionesalsuave@gmail.com'
    );

    foreach ( $order->get_items() as $item_id => $item ) {
        $product_id = $item->get_product_id();

        foreach ( $categorias_y_correos as $slug => $correo ) {
            if ( has_term( $slug, 'product_cat', $product_id ) ) {
                if ( strpos( $recipient, $correo ) === false ) {
                    $recipient .= ', ' . $correo;
                }
            }
        }
    }

    return $recipient;
}