Venkat Guna
Venkat Guna

Reputation: 21

Custom action button in WooCommerce admin orders that does the function of order-status

I have a added a custom order status "Manage orders" that does the work of generating courier packing slips (plugin supplied by the courier company). I need to create an action button for each individual order instead of managing it with bulk actions each time.

Order page showing the order-status from Bulk action dropdown which needs to be created as an action button in the action column that performs the same function

enter image description here

Upvotes: 0

Views: 1801

Answers (1)

Rajeev Singh
Rajeev Singh

Reputation: 1809

You should try this and change action_slug, CSS and icon accordingly

// Add your custom order status action button for orders stratus like : 'on-hold','pending', 'processing', 'completed', 'failed'

  add_filter( 'woocommerce_admin_order_actions', 'woo_order_status_actions_button', 100, 2 );

  function woo_order_status_actions_button( $actions, $order ) {

    // Display the button according to order status
    if ( $order->has_status( array( 'failed') ) ) {

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

// Set wooCommerce icon for Manage Order action button
add_action( 'admin_head', 'woo_custom_order_status_actions_button_css' );
function woo_custom_order_status_actions_button_css() {
    echo '<style>.view.manage_order::after { font-family: woocommerce; content: "\e005" !important; }</style>';
}

Upvotes: 1

Related Questions