在 WooCommerce 管理订单列表中添加自定义操作按钮 [英] Add a custom action button in WooCommerce admin order list

查看:54
本文介绍了在 WooCommerce 管理订单列表中添加自定义操作按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已遵循

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

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

是否有钩子可以应用这些按钮?
如何将其添加到 function.php 中?

谢谢

解决方案

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

<块引用>

对于 WooCommerce 3.3+ 版,请检查更新

I have followed this instructions to add a custom order status for my WooCommerce Orders.

I can't find a way to create a custom action button that changes the order status to my custom status from the admin order list page like this screenshot:

I would like this custom action button to be shown for the orders that have a "Processing" status.

I could not find any answer in WooCommerce documentation.

Is there a hook to apply these buttons?
How can I add it in the function.php?

Thank you

解决方案

To resume, you have created a custom order status 'wc-parcial' (with the instructions code provided in your question) and you need to add a related action button to orders admin list.

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

You need to use a custom function hooked in woocommerce_admin_order_actions filter hook

// 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>';
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

This code is tested and works. You will get that:

这篇关于在 WooCommerce 管理订单列表中添加自定义操作按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆