WooCommerce本身似乎沒有列印訂單的功能,因此必須透過外掛補足此功能
Print Invoice & Delivery Notes for WooCommerce
啟用後,如果想修改列印的內容,可以直接修改
woocommerce-delivery-notes/templates/print-order/print-content.php
這是我修改過後的版本,由於bundle會把原本的商品列印出來,容易造成同仁在理貨時出錯
WPC Product Bundles在製作組合內容時,組合商品的SKU留空,修過改過的印單內容使用條件 - SKU如果為空值則不顯示
除此之外,我還增加不顯示金額
底下為修改後的程式碼,置換後即可使用
<?php /** * Print order content. Copy this file to your themes * directory /woocommerce/print-order to customize it. * * @package WooCommerce Print Invoice & Delivery Note/Templates */ if ( ! defined( 'ABSPATH' ) ) { exit; } ?> <div class="order-branding"> <div class="company-logo"> <?php if ( wcdn_get_company_logo_id() ) : ?> <?php wcdn_company_logo(); ?> <?php endif; ?> </div> <div class="company-info"> <?php if ( ! wcdn_get_company_logo_id() ) : ?> <h1 class="company-name"><?php wcdn_company_name(); ?></h1> <?php endif; ?> <div class="company-address"><?php wcdn_company_info(); ?></div> </div> <?php do_action( 'wcdn_after_branding', $order ); ?> </div> <div class="order-addresses"> <div class="billing-address"> <h3><?php esc_attr_e( 'Billing Address', 'woocommerce-delivery-notes' ); ?></h3> <address> <?php if ( ! $order->get_formatted_billing_address() ) { esc_attr_e( 'N/A', 'woocommerce-delivery-notes' ); } else { echo wp_kses_post( apply_filters( 'wcdn_address_billing', $order->get_formatted_billing_address(), $order ) ); } ?> </address> </div> <div class="shipping-address"> <h3><?php esc_attr_e( 'Shipping Address', 'woocommerce-delivery-notes' ); ?></h3> <address> <?php if ( ! $order->get_formatted_shipping_address() ) { esc_attr_e( 'N/A', 'woocommerce-delivery-notes' ); } else { echo wp_kses_post( apply_filters( 'wcdn_address_shipping', $order->get_formatted_shipping_address(), $order ) ); } ?> </address> </div> <?php do_action( 'wcdn_after_addresses', $order ); ?> </div> <div class="order-info"> <h2><?php wcdn_document_title(); ?></h2> <ul class="info-list"> <?php $fields = apply_filters( 'wcdn_order_info_fields', wcdn_get_order_info( $order ), $order ); foreach ( $fields as $field ) : ?> <li> <strong><?php echo wp_kses_post( apply_filters( 'wcdn_order_info_name', $field['label'], $field ) ); ?></strong> <span><?php echo wp_kses_post( apply_filters( 'wcdn_order_info_content', $field['value'], $field ) ); ?></span> </li> <?php endforeach; ?> </ul> <?php do_action( 'wcdn_after_info', $order ); ?> </div> <div class="order-items"> <table> <thead> <tr> <th class="head-name"><span><?php esc_attr_e( 'Product', 'woocommerce-delivery-notes' ); ?></span></th> <th class="head-quantity"><span><?php esc_attr_e( 'Quantity', 'woocommerce-delivery-notes' ); ?></span></th> </tr> </thead> <tbody> <?php if ( count( $order->get_items() ) > 0 ) : foreach ( $order->get_items() as $item_id => $item ) : $product = apply_filters( 'wcdn_order_item_product', $item->get_product(), $item ); // 檢查商品是否存在及 SKU 是否為空,若為空則跳過該商品 if ( ! $product || empty( $product->get_sku() ) ) { continue; } ?> <tr> <td class="product-name"> <?php do_action( 'wcdn_order_item_before', $product, $order, $item ); ?> <span class="name"><?php echo wp_kses_post( $product->get_name() ); ?></span> <?php do_action( 'wcdn_order_item_after', $product, $order, $item ); ?> </td> <td class="product-quantity"> <span><?php echo esc_attr( apply_filters( 'wcdn_order_item_quantity', $item->get_quantity(), $item ) ); ?></span> </td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> <tfoot> <?php $totals_arr = $order->get_order_item_totals(); if ( $totals_arr ) : foreach ( $totals_arr as $total ) : ?> <tr> <td class="total-name"><span><?php echo wp_kses_post( $total['label'] ); ?></span></td> <td class="total-quantity"></td> </tr> <?php endforeach; ?> <?php endif; ?> </tfoot> </table> <?php do_action( 'wcdn_after_items', $order ); ?> </div> <div class="order-notes"> <?php if ( wcdn_has_customer_notes( $order ) ) : ?> <h4><?php esc_attr_e( 'Customer Note', 'woocommerce-delivery-notes' ); ?></h4> <?php wcdn_customer_notes( $order ); ?> <?php endif; ?> <?php do_action( 'wcdn_after_notes', $order ); ?> </div> <div class="order-thanks"> <?php wcdn_personal_notes(); ?> <?php do_action( 'wcdn_after_thanks', $order ); ?> </div> <div class="order-colophon"> <div class="colophon-policies"><?php wcdn_policies_conditions(); ?></div> <div class="colophon-imprint"><?php wcdn_imprint(); ?></div> <?php do_action( 'wcdn_after_colophon', $order ); ?> </div>
由於改到主程式的程式碼,因此如果遇到版本升級時,記得要把語法備份,等更新後再替換上去