2017-08-04 213 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

相關問題