Woocommerce 3.3+中的预览灯箱上用于管理订单列表的其他操作按钮 [英] Additional action buttons to admin order list on Preview Lightbox in Woocommerce 3.3+
问题描述
在Woocommerce管理员订单列表中,单击图标眼睛" ,它将在灯箱中打开订单的预览.该灯箱(预览)的底部有一些操作按钮,可用于更改订单状态.
In Woocommerce Admin orders list, when clicking the icon "eye" , 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.
我还有5个自定义订单状态,也想添加为操作按钮,但是我不知道我需要使用哪个挂钩.
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.
推荐答案
完成此操作的正确钩子是woocommerce_admin_order_preview_actions
过滤器钩子.
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:
- 状态段(不以"wc-"开头)作为键
- 状态标签名称
- 允许的状态数组标记(显示其当前状态操作按钮)
示例代码(此处为2个自定义假状态自定义1"和自定义2"):
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;
}
代码进入您的活动子主题(活动主题)的function.php文件中.经过测试,可以正常工作.
Code goes in function.php file of your active child theme (active theme). Tested and works.
这篇关于Woocommerce 3.3+中的预览灯箱上用于管理订单列表的其他操作按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!