Der Shop Blog
Vendidero – Germanized Pro – direktes Drucken aller Belege aus dem Backend
Meine Implementierung mit direktem Drucken ist sehr begehrt, daher veröffentliche ich Sie hiermit
// Add your custom order status action button (for orders with "processing" status)
add_filter( 'woocommerce_admin_order_actions', 'add_custom_order_status_actions_button', 100, 2 );
function add_custom_order_status_actions_button( $actions, $order ) {
// Display the button for all orders that have a 'processing' status
if ( $order->has_status( array( 'processing' ) ) ) {
//Prüfen ob alle Dokumente vorliegen:
//Rechnungen:
$invoices = wc_gzdp_get_invoices_by_order( $order );
$nr = 0;
$nl = 0;
$nd = 0;
foreach( $invoices as $invoice ) {
$file = $invoice->get_path();
$nr = $nr+1;
}
$shipments = wc_gzd_get_shipments_by_order( $order );
foreach( $shipments as $shipment ) {
if ( $packing_slip = wc_gzdp_get_packing_slip_by_shipment( $shipment->get_id() ) ) {
$file = $packing_slip->get_path();
$nl = $nl+1;
if ($shipment->has_label()) {
$label = $shipment->get_label();
$file = $label->get_file();
$nd = $nd+1;
}
}
}
if ($nr > 0 && $nl > 0 && $nd > 0)
{
// The key slug defined for your action button
$action_slug = 'printit';
$order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
// Set the action button
$actions[$action_slug] = array(
'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=print_to_printer&order_id=' . $order_id ) ),
'name' => __( 'Drucken', 'woocommerce' ),
'action' => $action_slug,
);
}
}
return $actions;
}
// Set Here the WooCommerce icon for your action button
add_action( 'admin_head', 'add_print_button_css' );
function add_print_button_css() {
$action_slug = "printit"; // The key slug defined for your action button
echo '<style>.wc-action-button-'.$action_slug.'::after { font-family: woocommerce !important; content: "\e01a" !important; }</style>';
}
add_action( 'wp_ajax_print_to_printer', 'print_to_printer');
function print_to_printer() {
$order_id = $_REQUEST['order_id'];
echo 'Order id: ' . $order_id . '<br>';
$order = wc_get_order($order_id);
//Rechnungen:
$invoices = wc_gzdp_get_invoices_by_order( $order );
foreach( $invoices as $invoice ) {
$file = $invoice->get_path();
echo $file . '<br>';
shell_exec('cp ' . $file . ' /data/print/');
}
//Lieferscheine:
// Get packing slips by shipment
$shipments = wc_gzd_get_shipments_by_order( $order );
foreach( $shipments as $shipment ) {
if ( $packing_slip = wc_gzdp_get_packing_slip_by_shipment( $shipment->get_id() ) ) {
$file = $packing_slip->get_path();
echo $file . '<br>';
shell_exec('cp ' . $file . ' /data/print/');
if ($shipment->has_label()) {
$label = $shipment->get_label();
$file = $label->get_file();
echo $file . '<br>';
shell_exec('cp ' . $file . ' /data/print/');
}
}
}
shell_exec('/data/print/print.sh');
$order->update_status('completed', 'printed to printer');
return wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=completed&order_id=' . $order_id));
}
