/*
Theme Name:   Xstore child
Theme URI:    https://xstore.8theme.com
Description:  XStore is a multi-purpose theme that offers the ultimate WordPress and WooCommerce synergy, providing a comprehensive, all-in-one solution.
Author:       8theme
Author URI:   https://www.8theme.com
Template:     xstore
Version:      1.0
Text Domain:  xstore-child
Tags: e-commerce, two-columns, left-sidebar, right-sidebar, custom-background, custom-colors, custom-header, custom-menu, custom-logo, featured-images, full-width-template, threaded-comments, accessibility-ready, rtl-language-support, footer-widgets, sticky-post, theme-options, translation-ready, ecommerce, woocommerce, shop, elementor, business, corporate, blog, news, light, dark
*/

function add_custom_brands_to_woocommerce() {
    // Define las marcas que quieres agregar
    $brands = [
        'Coca Cola', 
        'Branca', 
        'Cañuelas', 
        'Swift', 
        'Riera', 
        'Amanda', 
        'CBSE', 
        'Playadito', 
        'Rosamonte', 
        'CIF', 
        'Duplex', 
        'Gancia'
    ];

    // Asegúrate de que la taxonomía "brand" exista antes de agregar términos
    if (!taxonomy_exists('brand')) {
        error_log('La taxonomía "brand" no existe.');
        return;
    }

    // Recorre cada marca para agregarla si no existe
    foreach ($brands as $brand) {
        // Verifica si el término ya existe en la taxonomía "brand"
        if (!term_exists($brand, 'brand')) {
            $result = wp_insert_term($brand, 'brand');

            // Verifica si la inserción fue exitosa o devuelve error
            if (is_wp_error($result)) {
                error_log('Error al agregar la marca ' . $brand . ': ' . $result->get_error_message());
            } else {
                error_log('Marca agregada exitosamente: ' . $brand);
            }
        } else {
            error_log('La marca ' . $brand . ' ya existe.');
        }
    }
}
add_action('init', 'add_custom_brands_to_woocommerce', 20);
