php - 在 WooCommerce 管理订单列表中添加自定义操作按钮

标签 php wordpress woocommerce status orders

我已关注 this instructions为我的 WooCommerce 订单添加自定义订单状态。

我找不到创建自定义操作按钮的方法,该按钮将订单状态从管理订单列表页面更改为我的自定义状态,如下图所示:

This image shows where I want it to be.

我希望为具有“处理”状态的订单显示此自定义操作按钮。

我在 WooCommerce 文档中找不到任何答案。

是否有 Hook 可以应用这些按钮?
我如何将它添加到 function.php ?

谢谢

最佳答案

要恢复,您已创建自定义订单状态“wc-parcial”(使用问题中提供的说明代码),您需要向订单管理列表添加相关操作按钮。

For WooCommerce version 3.3+ check the update in this answer below



您需要使用 中 Hook 的自定义函数woocommerce_admin_order_actions 过滤钩
// Add your custom order status action button (for orders with "processing" status)
add_filter( 'woocommerce_admin_order_actions', 'add_custom_order_status_actions_button', 100, 2 );
function add_custom_order_status_actions_button( $actions, $order ) {
    // Display the button for all orders that have a 'processing' status
    if ( $order->has_status( array( 'processing' ) ) ) {

        // Get Order ID (compatibility all WC versions)
        $order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
        // Set the action button
        $actions['parcial'] = array(
            'url'       => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=parcial&order_id=' . $order_id ), 'woocommerce-mark-order-status' ),
            'name'      => __( 'Envio parcial', 'woocommerce' ),
            'action'    => "view parcial", // keep "view" class for a clean button CSS
        );
    }
    return $actions;
}

// Set Here the WooCommerce icon for your action button
add_action( 'admin_head', 'add_custom_order_status_actions_button_css' );
function add_custom_order_status_actions_button_css() {
    echo '<style>.view.parcial::after { font-family: woocommerce; content: "\e005" !important; }</style>';
}

代码位于事件子主题(或主题)的 function.php 文件或任何插件文件中。

此代码经过测试并有效。你会得到:

enter image description here

关于php - 在 WooCommerce 管理订单列表中添加自定义操作按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45516819/

相关文章:

css - 自定义 WP 主题 - 如何更改 CSS 中导航按钮的链接?

css - Chrome 开发者工具似乎找不到背景颜色

php - 访客客户检查 Woocommerce 订单账单电子邮件时可享受首单折扣

使用 Jquery Datepicker 进行 PHP MYSQL 日期范围搜索

php - 检测 PHP mysqli 中的空列值

php - 下拉列表和搜索字段 php

php - WordPress get_user_meta() - 是否有更好的方法来提取大量用户数据?

css - 这行 CSS 是什么意思? @media only screen and (min-device-width : 320px) and (max-device-width: 480px)

php - 如何在 WooCommerce 产品管理员中设置一个复选框以始终选中?

php - PHP 7.1 及更高版本的数据加密/解密