How can I automatically print when the order status changes?

The default setup of the plugin should print at the right time for the payment method type (e.g. for “manual” payment methods, like cash-on-delivery or cash-on-collection, it will print as soon as the order is placed; for electronic payments (e.g. PayPal, Stripe), it will print as soon as the order is paid). However, it may be that you have a need to send to Google Cloud Print based on a customised order status change. Here is how to do so.

Create the directory wp-content/mu-plugins in your WP install, if it does not already exist.

In that directory, create a file named wp-content/mu-plugins/order-status-change.php, with these contents:

<?php
add_filter('woocommerce_order_status_changed', 'my_woocommerce_order_status_changed', 10, 3);
function my_woocommerce_order_status_changed($order_id, $old_status, $new_status) {
 if ('on-hold' == $old_status && 'processing' == $new_status) {
 global $woocommerce_ext_printorders;
 $woocommerce_ext_printorders->woocommerce_print_order_go($order_id);
 }
}

You should change the statuses in the above (on-hold, processing), to match your desire setup. Other available statuses in WooCommerce by default are: failed, completed, refunded.

If someone pays using a payment method (e.g. cash-on-delivery) which triggers an immediate print-out when the order is placed, you can suppress that with this fragment:

add_filter('woocommerce_print_orders_print_order_upon_processed', '__return_false');

Posted in: WooCommerce Google Cloud Print Automatic Printing