0

I am trying to figure out how to create downloadable woocommerce products. Trouble is syntax for the --downloads argument for $ wp wc product create.

It appears that the downloads argument should be one ore more objets having "id", "name", "file" specifications. The toughest one to figure is "id". I tried using the specs for a download file associated with another product. Still get an [] empty value for that new product when I ask:

$ wp wc product list --fields=id,name,downloads 
$ wp wc product create --name="CLI Test Downloads" --type=simple  --regular_price=20 --downloadable=true --downloads=[{"id":"2d40862d-0044-4da6-bd87-0e94bf5531d6","name":"e-SIGNES-53no2.pdf","file":"https:\/\/ventardlab.info\/wp-content\/uploads\/2019\/01\/e-53no2.pdf"}]

I get no error message, just that product is created. But when I check the new product in the WordPress dashboard, there are no download file included.

leymannx
  • 5,138
  • 5
  • 45
  • 48

1 Answers1

1

I found the answer by myself after browsing other posts under tag of Stack Overflow.

Solution is quite simple: enclose the --downloads value within single quotes.

For example --downloads=' [ { .... } ] ' with the appropriate syntax inside the wp wc object. VoilĂ !

leymannx
  • 5,138
  • 5
  • 45
  • 48