Please give an example of a command that allows you to add a picture to it when creating a product through the CLI.

  • Try to write more detailed questions. Explain exactly what you see the problem, how to reproduce it, what you want to get as a result, etc. - Nicolas Chabanovsky
  • What is CLI ?? - Valery Emelyanov
  • @ Valery Yemelyanov Command Line Interface, en.wikipedia.org/wiki/CLI - Nick Volynkin

1 answer 1

Let's examine the includes/cli/class-wc-cli-product.php .

The create method expects information about pictures under the key images .

Here is the piece of code responsible for this:

 if ( isset( $data['images'] ) ) { $this->save_product_images( $id, $data['images'] ); } 

If we study the save_product_images method, it becomes clear that for each picture the following keys are recognized: id , position and src , where src is the URL to our picture, and id is actually an attachment_id .

As I understand it, if you specify id , a picture from the gallery with the specified id will be loaded. If src is specified, the image will be received at the specified url.

Here is the WP CLI support article in:
Sneak Peek: WP CLI Support in WooCommerce 2.5

If I correctly understood the method of parsing, then the picture should load something like this:

 wp wc product create --images.0.src="http://placehold.it/100x100.png?text=1" 

images.0.src will be expanded to the following structure:

 array( 'images' => array( 0 => array( 'src' => 'http://placehold.it/100x100.png?text=1' ) ) ) 

I recommend you to familiarize yourself with the file includes/cli/class-wc-cli-product.php , since I didn’t work with WP CLI and I can check this command only in the evening.


Update

Checked this option team. Everything is created as intended.

Refinement on the pictures:

 Картинки передаются массивом, где каждый элемент может быть задан по его индексу: * images * images.size * images.0.id * images.0.created_at * images.0.updated_at * images.0.src * images.0.title * images.0.alt * images.0.position 

Command execution:

enter image description here

Result:

enter image description here

  • cmder some kind of third-party console? Pleased the shell prompt in the form of lambda) - Nick Volynkin
  • @NickVolynkin Yes, this is a third-party console for Windows. http://cmder.net/ . I constantly use it - VenZell