douwen3973 2018-10-03 19:02
浏览 67
已采纳

在Woocommerce 3.3+中预览灯箱上的管理员订单列表的附加操作按钮

In Woocommerce Admin orders list, when clicking the icon "eye" enter image description here, it opens a preview of the order in a Lightbox. At the bottom of that Lightbox (preview), there are some actions buttons that allow to change the order status.

I have 5 more custom order statuses that I would like to add as action buttons too, but I don't know which hook I need to use.

Does anyone know how to add more buttons to that area?

Any help or advice is appreciated.

  • 写回答

1条回答 默认 最新

  • drkwpgrdb092239314 2018-10-03 20:33
    关注

    The correct hook to get this done is woocommerce_admin_order_preview_actions filter hook.

    You will need to define in the function below in a multidimensional array your custom order statuses data, one by one as follow, to get an action button for each:

    • The status slug (without starting with "wc-") as a key
    • The status label name
    • The allowed statuses array slugs (to display the current status action button for)

    The example code (here for 2 custom fake statuses "Custom One" and "Custom two"):

    add_filter( 'woocommerce_admin_order_preview_actions', 'additional_admin_order_preview_buttons_actions', 25, 2 );
    function additional_admin_order_preview_buttons_actions( $actions, $order ){
        // Below set your custom order statuses (key / label / allowed statuses) that needs a button
        $custom_statuses = array(
            'custom_one' => array( // The key (slug without "wc-")
                'label'     => __("Custom One", "woocommerce"), // Label name
                'allowed'   => array( 'pending', 'on-hold', 'processing', 'custom_two' ), // Button displayed for this statuses (slugs without "wc-")
            ),
            'custom_two' => array( // The key (slug without "wc-")
                'label'     => __("Custom Two", "woocommerce"), // Label name
                'allowed'   => array( 'pending', 'on-hold', 'processing', 'custom_one' ), // Button displayed for this statuses (slugs without "wc-")
            ),
        );
    
        // Loop through your custom orders Statuses
        foreach ( $custom_statuses as $status_slug => $values ){
            if ( $order->has_status( $values['allowed'] ) ) {
                $actions['status']['actions'][$status_slug] = array(
                    'url'    => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status='.$status_slug.'&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ),
                    'name'   => $values['label'],
                    'title'  => __( 'Change order status to', 'woocommerce' ) . ' ' . strtolower($values['label']),
                    'action' => $status_slug,
                );
            }
        }
        return $actions;
    }
    

    Code goes in function.php file of your active child theme (active theme). Tested and works.

    enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。