Prevent duplicate prints

If you are experiencing duplicated prints of an order, there might be a plugin or some other code on your website causing the print trigger to be fired twice for an order.

To guard against this, the following snippet can be used to prevent an order from being printed if it has already been printed within the last 2 minutes. This should essentially solve any duplicate prints of a single order.

Note that this snippet also applies on the admin order edit screen. So if you try to manually print an order multiple times from the admin oder edit screen, then it would not work until the two(2) minutes has passed.

If you do not want the code to apply on the admin order edit screen then you can delete the add_filter('printus__admin_printnode_job_data', 'sl_cc_printus_prevent_duplicates'); line from the snippet below.

function sl_cc_printus_prevent_duplicates($job_data){

$order_id = (int) $job_data['order_id'];
$last_printed = (int) get_transient('printus_last_printed_order');

if( $last_printed === $order_id ){
	return '';
}
	
set_transient('printus_last_printed_order', $order_id, 2 * MINUTE_IN_SECONDS);
	
return $job_data;
}
add_filter('printus__printnode_job_data', 'sl_cc_printus_prevent_duplicates');
add_filter('printus__admin_printnode_job_data', 'sl_cc_printus_prevent_duplicates');
Scroll to Top