I have a payment method for which I want to print as soon as an order is placed

With our WooCommerce automatic order printing plugin, for some payment methods (e.g. cash on collection, BACS transfer) it makes sense for the print-out to be done instantly on order creation, instead of (as for automated/electronic payment methods, e.g. PayPal, card payment) when payment has been made.

The plugin contains a default list of such payment methods. However, your WooCommerce store may have other payment methods added by other extensions that should also come into this category.

To do this, you can add the code below as an mu-plugin, or in your child theme’s functions.php, or as a snippet (whatever method you prefer for adding code to your site). You will need to change method_id for the true internal identifier of the new payment gateway. You can discover what this is by reading its code, or asking its supplier.

add_filter('woocommerce_print_orders_order_now', 'my_woocommerce_print_orders_order_now', 10, 3);
function my_woocommerce_print_orders_order_now($print_now, $payment_method, $order) {
return ('method_id' == $payment_method) ? true : $print_now;
}

If, after doing so, you get the infamous WordPres “white screen of death”, then you accidentally introduced a typing mistake somewhere, and should undo it.

Posted in: WooCommerce Automatic Order Printing