V
V
Vadim Timoshenko2020-05-25 19:22:51
SQL
Vadim Timoshenko, 2020-05-25 19:22:51

How to quickly create 99999 simple products?

You need to upload 99999 simple downloadable products to woocommerce, which differ from each other only in the name, article number, and number in the URL. This is what the piece of .csv file looks like that I'm trying to upload to the site.

"Артикул";"Имя";"В наличии?";"Запасы";"Базовая цена";"URL загрузки";"Лимит загрузок";"Тип"
"00001";"00001";1;1;99;"/ticket.png?number=00001";1;"simple, downloadable"
"00002";"00002";1;1;99;"/ticket.php?number=00002";1;"simple, downloadable"
"00003";"00003";1;1;99;"/ticket.php?number=00003";1;"simple, downloadable"
"00004";"00004";1;1;99;"/ticket.php?number=00004";1;"simple, downloadable"
"00005";"00005";1;1;99;"/ticket.php?number=00005";1;"simple, downloadable"
"00006";"00006";1;1;99;"/ticket.php?number=00006";1;"simple, downloadable"
"00007";"00007";1;1;99;"/ticket.php?number=00007";1;"simple, downloadable"
"00008";"00008";1;1;99;"/ticket.php?number=00008";1;"simple, downloadable"
"00009";"00009";1;1;99;"/ticket.php?number=00009";1;"simple, downloadable"


It takes a very long time to load. Here I think - maybe a SQL query is easier to do and faster? Or is there some better solution?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan Hasanli, 2020-05-25
@azerphoenix

Adding products or SQL records with a query is not a good idea, because in this case you are bypassing the VI.
It is better to use Woocommerce REST API capabilities. Or as an option plugin WP All Import + Woocommerce Addon and import from CSV file.

W
WP Panda, 2020-05-25
@wppanda5 WooCommerce

You can’t throw it directly, of course, but anything unpleasant is possible, because when you add a record, a lot of things happen.
So, test how many as much as possible and you can throw records in one pass using standard means. everything is there except to pull up the thumbnail.

<?php
  /**
   * @package TAXO CRM
   * @author  WP_Panda
   * @version 0.2.1
   */

  require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );

  $metas = [
    'key_1' => 1,
    'key_2' => 1,
    'key_3' => 1,
    'key_3' => 1
  ];

  $post_data = [
    'post_content'  => 'Контент контент контент',
    'post_status'   => 'publish',
    'post_author'   => 1,
    'post_category' => [ 8, 39 ]
  ];

  $start = microtime(true);

  $i = 1;
  while ( $i <= 1000 ) {
    $post_data[ 'post_title' ] = 'Запись ' . $i;

    $post_id = wp_insert_post( $post_data );

    foreach ( $metas as $meta_key => $meta_val ) {
      update_post_meta( $post_id, $meta_key, $meta_val );
    }

    $i ++;
  }

  $time = microtime(true) - $start;
  printf( 'Время выполнения: %s мс', $time );

I got 1000 on a weak shared in 24 seconds.
Accordingly, taking into account the fact that your file contains 99 times more positions, wrap it, for example, in an Ajax handler in which there will be an indication of which lines to pour, because 99k at a time is a bit too much and it will be necessary progressively, respectively, in 40-45 minutes everything will be flooded with you
If instead
of update_post_meta
use
add_metadata
It will be even faster

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question