Script Update Key Feature

// Script update Vorteile to Product Key Features
// add_action('init', 'tzn_update_vorteile_to_product_key_features');
if (!function_exists('tzn_update_vorteile_to_product_key_features')) {
    function tzn_update_vorteile_to_product_key_features()
    {
        if (current_user_can('administrator') && isset($_GET['update_vorteile_to_product_key_features']) && $_GET['update_vorteile_to_product_key_features'] == "1") {
            $query = new WC_Product_Query(
                array(
                    'limit' => -1,
                    'orderby' => 'ID',
                    'order' => 'DESC',
                    'return' => 'ids',
                ));
            $products = $query->get_products();
            if ($products && count($products) > 0) {
                foreach ($products as $product_id) {
                    // echo "product_id: ".$product_id."<br>";
                    $product_key = get_post_meta($product_id, 'product_key_features', true);
                    $vorteile = get_field('vorteile', $product_id);
                    if($product_key == "" && $vorteile != ""){
                        // update_post_meta( $product_id, 'product_key_features', $vorteile );
                        echo 'Udated: '.$product_id."</br>";
                        
                        // update_post_meta( $product_id, 'update_vorteile_to_product_key_features', 1 );
                    
                    }
                }
            }
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *