2017-08-04 126 views
2

我已按照this instructions为我的WooCommerce订单添加自定义订单状态。在WooCommerce管理订单列表中添加一个自定义操作按钮

我无法找到一个方法来创建自定义操作按钮,该订单状态从管理订单列表页修改我的自定义状态这样的截图:

This image shows where I want it to be.

我想这个自定义将显示具有“处理”状态的订单的操作按钮。

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

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

谢谢

回答

5

更新版本的答案下面WooCommerce 3.3+

要继续,你已经创建了一个自定义的订单状态“WC-parcial”(在提供的代码的说明你的问题),你需要添加一个相关的动作按钮来下令管理列表。

你需要使用挂钩自定义功能在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

+0

它的工作原理。非常感谢! –

0

更新版本Woocommerce 3.3+

要恢复,您创建一个自定义的订单状态 'WC-parcial'(与指令码提供在你的问题中),你需要添加一个相关的操作按钮来下单管理列表。

新代码:

// 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'))) { 

     // The key slug defined for your action button 
     $action_slug = 'parcial'; 

     // Set the action button 
     $actions[$action_slug] = array(
      'url'  => wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce_mark_order_status&status=parcial&order_id=' . $order->get_id()), 'woocommerce-mark-order-status'), 
      'name'  => __('Envio parcial', 'woocommerce'), 
      'action' => $action_slug, 
     ); 
    } 
    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() { 
    $action_slug = "parcial"; // The key slug defined for your action button 

    echo '<style>.wc-action-button-'.$action_slug.'::after { font-family: woocommerce !important; content: "\e029" !important; }</style>'; 
} 

代码放在您的活动子主题(或主题)的function.php文件。

测试和工程

enter image description here

相关问题