/**
 * Theme Name: Rey Child
 * Theme URI: http://reytheme.com/
 * Description: This is a child theme of Rey.
 * Author: Marius H.
 * Author URI:  https://twitter.com/mariushoria
 * Template: rey
 * Version: 1.0.0
 * License: General Public License
 * License URI: http://www.gnu.org/licenses/gpl.html
 * Text Domain: rey-child
 */

add_action('init', 'poner_en_borrador_productos_sin_imagen_destacada');

function poner_en_borrador_productos_sin_imagen_destacada() {
    // Solo ejecuta si el usuario es administrador (para evitar que corra en el frontend)
    if (!current_user_can('manage_woocommerce')) {
        return;
    }

    $args = array(
        'post_type'      => 'product',
        'post_status'    => 'publish',
        'posts_per_page' => -1,
        'meta_query'     => array(
            array(
                'key'     => '_thumbnail_id',
                'compare' => 'NOT EXISTS',
            ),
        ),
    );

    $productos_sin_imagen = get_posts($args);

    foreach ($productos_sin_imagen as $producto) {
        wp_update_post(array(
            'ID'          => $producto->ID,
            'post_status' => 'draft',
        ));
    }
}
