/*
Theme Name: Hello Elementor Child
Theme URI: https://elementor.com/hello-theme/?utm_source=wp-themes&utm_campaign=theme-uri&utm_medium=wp-dash
Template: hello-elementor
Author: Elementor Team
Author URI: https://elementor.com/?utm_source=wp-themes&utm_campaign=author-uri&utm_medium=wp-dash
Description: Hello Elementor is a lightweight and minimalist WordPress theme that was built specifically to work seamlessly with the Elementor site builder plugin. The theme is free, open-source, and designed for users who want a flexible, easy-to-use, and customizable website. The theme, which is optimized for performance, provides a solid foundation for users to build their own unique designs using the Elementor drag-and-drop site builder. Its simplicity and flexibility make it a great choice for both beginners and experienced Web Creators.
Tags: accessibility-ready,flexible-header,custom-colors,custom-menu,custom-logo,featured-images,rtl-language-support,threaded-comments,translation-ready
Version: 3.4.5.1762950707
Updated: 2025-11-12 12:31:47

*/

/**
 * 🔹 Agregar campos personalizados ("Incluye" y "No incluye") al editor de productos
 */
add_action('woocommerce_product_options_general_product_data', 'outsur_agregar_campos_personalizados');
function outsur_agregar_campos_personalizados() {

    // Campo "Incluye"
    woocommerce_wp_textarea_input( array(
        'id'          => '_incluye',
        'label'       => 'Incluye',
        'placeholder' => 'Ej: Guía profesional, transporte, refrigerio...',
        'desc_tip'    => true,
        'description' => 'Agrega una lista o descripción de lo que está incluido en el taller.',
    ));

    // Campo "No incluye"
    woocommerce_wp_textarea_input( array(
        'id'          => '_no_incluye',
        'label'       => 'No incluye',
        'placeholder' => 'Ej: Equipos personales, almuerzo, alojamiento...',
        'desc_tip'    => true,
        'description' => 'Agrega una lista o descripción de lo que NO está incluido.',
    ));
}

/**
 * 🔹 Guardar los valores de los campos al actualizar el producto
 */
add_action('woocommerce_process_product_meta', 'outsur_guardar_campos_personalizados');
function outsur_guardar_campos_personalizados( $post_id ) {
    $incluye    = isset($_POST['_incluye']) ? sanitize_textarea_field($_POST['_incluye']) : '';
    $no_incluye = isset($_POST['_no_incluye']) ? sanitize_textarea_field($_POST['_no_incluye']) : '';

    update_post_meta($post_id, '_incluye', $incluye);
    update_post_meta($post_id, '_no_incluye', $no_incluye);
}

/**
 * 🔹 Mostrar los campos personalizados en la página del producto
 */
add_action('woocommerce_single_product_summary', 'outsur_mostrar_campos_personalizados', 25);
function outsur_mostrar_campos_personalizados() {
    global $post;

    $incluye    = get_post_meta($post->ID, '_incluye', true);
    $no_incluye = get_post_meta($post->ID, '_no_incluye', true);

    if ( !empty($incluye) || !empty($no_incluye) ) {
        echo '<div class="detalles-incluye-no-incluye" style="margin-top:30px;">';

        if (!empty($incluye)) {
            echo '<h3 style="margin-bottom:5px;">Incluye</h3>';
            echo '<p>' . nl2br(esc_html($incluye)) . '</p>';
        }

        if (!empty($no_incluye)) {
            echo '<h3 style="margin-top:20px;margin-bottom:5px;">No incluye</h3>';
            echo '<p>' . nl2br(esc_html($no_incluye)) . '</p>';
        }

        echo '</div>';
    }
}
