@@ -90,6 +90,7 @@ public static function orders( $args, $assoc_args ) {
9090 }
9191
9292 if ( $ amount > 0 ) {
93+ static ::disable_emails ();
9394 $ progress = \WP_CLI \Utils \make_progress_bar ( 'Generating orders ' , $ amount );
9495 for ( $ i = 1 ; $ i <= $ amount ; $ i ++ ) {
9596 Generator \Order::generate ( true , $ assoc_args );
@@ -120,6 +121,7 @@ public static function orders( $args, $assoc_args ) {
120121 public static function customers ( $ args , $ assoc_args ) {
121122 list ( $ amount ) = $ args ;
122123
124+ static ::disable_emails ();
123125 $ progress = \WP_CLI \Utils \make_progress_bar ( 'Generating customers ' , $ amount );
124126 for ( $ i = 1 ; $ i <= $ amount ; $ i ++ ) {
125127 Generator \Customer::generate ();
@@ -128,6 +130,26 @@ public static function customers( $args, $assoc_args ) {
128130 $ progress ->finish ();
129131 WP_CLI ::success ( $ amount . ' customers generated. ' );
130132 }
133+
134+ /**
135+ * Disable sending WooCommerce emails when generating objects.
136+ */
137+ protected static function disable_emails () {
138+ $ wc_emails = \WC_Emails::instance ();
139+ remove_action ( 'woocommerce_email_header ' , array ( $ wc_emails , 'email_header ' ) );
140+ remove_action ( 'woocommerce_email_footer ' , array ( $ wc_emails , 'email_footer ' ) );
141+ remove_action ( 'woocommerce_email_order_details ' , array ( $ wc_emails , 'order_downloads ' ), 10 , 4 );
142+ remove_action ( 'woocommerce_email_order_details ' , array ( $ wc_emails , 'order_details ' ), 10 , 4 );
143+ remove_action ( 'woocommerce_email_order_meta ' , array ( $ wc_emails , 'order_meta ' ), 10 , 3 );
144+ remove_action ( 'woocommerce_email_customer_details ' , array ( $ wc_emails , 'customer_details ' ), 10 , 3 );
145+ remove_action ( 'woocommerce_email_customer_details ' , array ( $ wc_emails , 'email_addresses ' ), 20 , 3 );
146+ remove_action ( 'woocommerce_low_stock_notification ' , array ( $ wc_emails , 'low_stock ' ) );
147+ remove_action ( 'woocommerce_no_stock_notification ' , array ( $ wc_emails , 'no_stock ' ) );
148+ remove_action ( 'woocommerce_product_on_backorder_notification ' , array ( $ wc_emails , 'backorder ' ) );
149+ remove_action ( 'woocommerce_created_customer_notification ' , array ( $ wc_emails , 'customer_new_account ' ), 10 , 3 );
150+ remove_filter ( 'woocommerce_email_footer_text ' , array ( $ wc_emails , 'replace_placeholders ' ) );
151+
152+ }
131153}
132154WP_CLI ::add_command ( 'wc generate products ' , array ( 'WC\SmoothGenerator\CLI ' , 'products ' ) );
133155WP_CLI ::add_command ( 'wc generate orders ' , array ( 'WC\SmoothGenerator\CLI ' , 'orders ' ), array (
0 commit comments