php - 在 Woocommerce 3.3+ 中的 Preview Lightbox 上管理订单列表的附加操作按钮
问题描述
在 Woocommerce Admin 订单列表中,单击“眼睛”图标时,会在 Lightbox 中打开订单预览。在该灯箱(预览)的底部,有一些允许更改订单状态的操作按钮。
我还有 5 个自定义订单状态,我也想添加为操作按钮,但我不知道我需要使用哪个钩子。
有谁知道如何在该区域添加更多按钮?
任何帮助或建议表示赞赏。
解决方案
完成此操作的正确钩子是woocommerce_admin_order_preview_actions
过滤器钩子。
您需要在下面的函数中的多维数组中定义您的自定义订单状态数据,如下所示,以获得每个操作按钮:
- status slug(不以“wc-”开头)作为键
- 状态标签名称
- 允许的状态数组 slugs(显示当前状态操作按钮)
示例代码(此处为 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 文件中。测试和工作。
推荐阅读
- python - 有条件地重命名多个列名
- java - JUnit AssertionError:期望代码引发一个 throwable
- jsf - 如何禁用 myfaces 缓存资源 URL?
- ios - 自 xcode 11 以来,debugDescription 中的 UISwitch 未显示值
- statistics - 如何在 SPSS 的自动重新编码中应用模板?
- python - 熊猫与列上的条件合并
- javascript - 如何使用 Java 处理带有 Selenium WebDriver 的 Firefox 中的身份验证弹出窗口
- javascript - 使用javascript的表格单元格内的时间差
- c - OpenCL 内核通过批处理实现 im2col
- python - 从分组数据中创建一个新列