How to send print job to multiple printers of the same kind

The following code adds the ability to have the same print job be sent to multiple printers of the same kind. Printus will adopt your same settings that you’ve saved in the plugin but it will simply send the job to the other designated printers.

This means that if you’re using Nimbus template (which is a template for receipt printers), then it is assumed that your other printers are receipt printers as well as nothing but the Printer ID is changed in the print job.

function sl_cc_printus_print_multiple_printers($request_info){

  $endpoint = $request_info['endpoint'] ?? '';
	
	if($endpoint !== 'printjobs'){
		return;
	}
	
	
	if(!class_exists('\Printus\Models\PluginSettings\ApiSettingsModel')){
		return;
	}
	
	$printer_ids = array(
	 12345678, // Replace with ID of printer (which you can find inside PrintNode).
	);
	
	$url = "https://api.printnode.com/printjobs";
	$api_key = ( new \Printus\Models\PluginSettings\ApiSettingsModel() )->get_api_key();
	$api_key = base64_encode($api_key);
	
	foreach($printer_ids as $printer_id){
		
		$data = $request_info['data'] ?? '';
		
		if(empty($data)){
			continue;
		}
		
		$data['printerId'] = $printer_id;
		
		wp_remote_request(
			$url,
			array(
				'method'    => 'POST',
				'sslverify' => false,
				'headers'   => array(
					'Content-Type'  => 'application/x-www-form-urlencoded',
					'Authorization' => "Basic $api_key",
				),
				'body'      => $data,
				'timeout'   => 30,
			)
		);
		
	}
	
}
add_action('printus_successful_external_request', 'sl_cc_printus_print_multiple_printers');

$printer_ids is an array which means you can enter multiple Printer IDs and all of them will receive the job, example:

$printer_ids = array(
	 12345678,
	 87654321,
	 00000000,
);
Scroll to Top