【问题标题】:add custom order status in Print Invoice & Delivery Notes for WooCommerce plugin在 WooCommerce 插件的打印发票和交货单中添加自定义订单状态
【发布时间】:2021-09-16 18:09:45
【问题描述】:

我想使用 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 );

【问题讨论】:

    标签: php wordpress woocommerce plugins hook-woocommerce


    【解决方案1】:

    您非常接近正确的代码 sn-p。请在下面找到正确的代码。

    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

    【讨论】:

      猜你喜欢
      • 2023-04-03
      • 2015-06-29
      • 2021-07-14
      • 2019-11-13
      • 1970-01-01
      • 2018-07-14
      • 2018-12-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多