Create Print Job Based on Payment Method

You can create custom print jobs using your underlying Printus configuration by making use of the PrintOrderController class. In the code snippet below, we’re performing a print job if the payment method used for the order is “Cash on Delivery”.

This is useful if you’re making use of the “Payment Complete” trigger but you’re also allowing customers to pay using “Cash on Delivery”. Under normal circumstances, when using Payment Complete as the print trigger inside Printus settings, it would not print for payment methods that do not fire the woocommerce_payment_complete hook. The “Cash on Delivery” payment method is one of those payment methods that do not fire that hook.

Using the snippet below, we’re detecting the payment method and then performing a print job using the PrintOrderController class.

function sl_cc_printus_multiple_triggers($order_id, $posted_data, $order)
{

    $payment_method = $posted_data['payment_method'] ?? '';

    if (empty($payment_method)) {
        return;
    }

    if ($payment_method !== 'cod') { // Only proceed if payment method is Cash on Delivery.
        return;
    }

    if (class_exists('\Printus\Controllers\API\Order\PrintOrderController') === false) {
        return;
    }

    (new \Printus\Controllers\API\Order\PrintOrderController())->sendPrintJob($order_id);

}
add_action('woocommerce_checkout_order_processed', 'sl_cc_printus_multiple_triggers', 10, 3);
Scroll to Top