woocommerce / wc-smooth-generator

Smooth product, customer and order generation for WooCommerce
315 stars 49 forks source link

Add --status argument for Orders #46

Closed shiki closed 3 years ago

shiki commented 3 years ago

Why

I want to use this generator in a cron job to periodically create orders for a test site. And I want to be able to receive push notifications on the WooCommerce iOS app every time an order is created. I'm mainly using this for dog-fooding the iOS app.

The problem is that, the iOS app will only receive push notifications if the Order's status is processing. And this generator randomizes the order status so it can be tricky to rely on. It'd be great if I can specify what status to use for the generated orders.

Changes

This adds a --status argument to generate orders with a specific status. For example, running this command would generate orders with the processing status:

wp wc generate orders 10 --status=processing

Error Handling

If the user enters an invalid status, the order will be set to pending instead. This is done automatically by WC_Order.set_status().

Testing

  1. Run this command:

    wp wc generate orders 10 --status=completed
  2. Confirm that 10 orders were created with the “Completed” status.
  3. Run this command:

    wp wc generate orders 10 
  4. Confirm that 10 orders were created with random statuses.