在 WooCommerce 插件的打印发票和送货单中添加自定义订单状态

add custom order status in Print Invoice & Delivery Notes for WooCommerce plugin

我想使用 WooCommerce 插件的发票和送货单在打印页面中添加订单状态 我试过这段代码,但没有用,问题是什么? 我的代码:

function add_order_status( $fields, $order ) {
    $new_fields = array();

    if( get_post_meta( $order->get_status(), 'order-status', true ) ) {
        $new_fields['order-status'] = array( 
            'label' => 'Order Status',
            'value' => get_post_meta( $order->get_status(), 'order-status', true )
        );
    }
    return array_merge( $fields, $new_fields );
}
add_filter( 'wcdn_order_info_fields', 'add_order_status', 10, 2 );

您非常接近正确的代码片段。请在下面找到正确的代码。

function bks_add_extra_field( $fields, $order ) {
    $new_fields = array();
        
    if( $order->get_status() ) {
        $new_fields['status'] = array( 
            'label' => 'Order Status',
            'value' => $order->get_status(),
        );
    }

    return array_merge( $fields, $new_fields );
}
add_filter( 'wcdn_order_info_fields', 'bks_add_extra_field', 10, 2 );

截图:


对于希望为 WooCommerce 插件自定义 发票和送货单的任何其他人,您可以在此处找到所有挂钩的列表:

https://github.com/TycheSoftwares/Print-Invoice-Delivery-Notes-for-WooCommerce/wiki/Hooks-and-Filters-for-compatibility-and-minor-changes