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

Rod*_*mes 2 php wordpress status orders woocommerce

我已按照此说明为我的WooCommerce订单添加自定义订单状态.

我无法找到一种方法来创建自定义操作按钮,将管理订单列表页面中的订单状态更改为我的自定义状态,如此屏幕截图:

此图像显示了我想要的位置.

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

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

是否有应用这些按钮的钩子?
我怎样才能添加它function.php

谢谢

Loi*_*tec 5

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

对于WooCommerce 3.3及以上版本检查更新这个答案如下

您需要使用挂钩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>';
}
Run Code Online (Sandbox Code Playgroud)

代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中.

此代码经过测试和运行.你会得到的:

在此输入图像描述