Skip to content

Instantly share code, notes, and snippets.

@ChromeOrange
Created September 18, 2014 00:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChromeOrange/3cb3a16a6560795b972d to your computer and use it in GitHub Desktop.
Save ChromeOrange/3cb3a16a6560795b972d to your computer and use it in GitHub Desktop.
Add custom order status to WooCommerce 2.2, add to theme functions.php
/**
* Add custom status to order list
*/
add_action( 'init', 'register_custom_post_status', 10 );
function register_custom_post_status() {
register_post_status( 'wc-backorder', array(
'label' => _x( 'Back Order', 'Order status', 'woocommerce' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Back Order <span class="count">(%s)</span>', 'Back Order <span class="count">(%s)</span>', 'woocommerce' )
) );
}
/**
* Add custom status to order page drop down
*/
add_filter( 'wc_order_statuses', 'custom_wc_order_statuses' );
function custom_wc_order_statuses( $order_statuses ) {
$order_statuses['wc-backorder'] = _x( 'Back Order', 'Order status', 'woocommerce' );
return $order_statuses;
}
/**
* Add order status icon CSS
*/
add_action('admin_head', 'backorder_font_icon');
function backorder_font_icon() {
echo '<style>
.widefat .column-order_status mark.backorder:after{
font-family:WooCommerce;
speak:none;
font-weight:400;
font-variant:normal;
text-transform:none;
line-height:1;
-webkit-font-smoothing:antialiased;
margin:0;
text-indent:0;
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
text-align:center;
}
.widefat .column-order_status mark.backorder:after{
content:"\e012";
color:#ff0000;
}
</style>';
}
@indiraa
Copy link

indiraa commented Sep 26, 2014

How can the new order status be added to the Actions drop down? I want to mark a large amount of order with my new order status.

@David-Woodthorpe
Copy link

You could use the following example as a starting point:

    function add_quote_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-quote'] = 'Quote';
        }
    }

    return $new_order_statuses; 

Using this on our site Evolution Signs as part of our online quote system.

@andycaps
Copy link

I used the above code and it deleted a record?

I changed the code to:

'wp-backorders' to 'waitingforshipping'
'Back Orders' to 'Waiting for Shipping'
'function backorder_font_icon' to 'function waitingforshiping_font_icon'

The dropdown worked great but when I updated from processing to waiting for shipping the record disappeared. Luckily I had an original copy of the order so was able to reenter the order.

What did I do wrong????

Oh by the way - not sure where the code went so put it at the very bottom of the existing code - is it that I did wrong?

@lightson
Copy link

lightson commented Oct 5, 2015

Very useful snippet, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment