0
votes

I added a custom WooCommerce status with the following code and want

function register_shipped_status() {

    register_post_status( 'wc-shipped', array(
        'label'                     => 'Shipped',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Versendet <span class="count">(%s)</span>', 'Versendet <span class="count">(%s)</span>' )
    ) );

}
add_action( 'init', 'register_shipped_status' );

function add_shipped_to_order_statuses( $order_statuses ) {

    $new_order_statuses = array();

    // add new order status after processing
    foreach ( $order_statuses as $key => $status ) {
        $new_order_statuses[ $key ] = $status;
        if ( 'wc-processing' === $key ) {
            $new_order_statuses['wc-shipped'] = 'Versendet';
        }
    }

    return $new_order_statuses;

}
add_filter( 'wc_order_statuses', 'add_shipped_to_order_statuses' );

This is working fine. The WooCommerce status is selectable, but I want the action button "completed" in the order list.

See screenshot:

enter image description here

Is there any way to add this WooCommerce button to all orders with my custom WooCommerce status?

1

1 Answers

1
votes

To have the "complete" action button for Orders with custom order status, use the following:

add_filter( 'woocommerce_admin_order_actions', 'customize_admin_order_actions', 10, 2 );
function customize_admin_order_actions( $actions, $order ) {
    // Display the "complete" action button for orders that have a 'shipped' status
    if ( $order->has_status('shipped') ) {
        $actions['complete'] = array(
            'url'    => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=completed&order_id=' . $order->get_id() ), 'woocommerce-mark-order-status' ),
            'name'   => __( 'Complete', 'woocommerce' ),
            'action' => 'complete',
        );
    }
    return $actions;
}

Code goes in functions.php file of your active child theme (or active theme). Tested and works.

enter image description here

Related: Add a custom order status "Shipped" in Woocommerce