0
votes

I would like to automatically update my WooCommerce order status to wc-partialRefunded when the order refunded partially.

I have successfully created the custom order status and not sure how to count the order quantity and get the result.

Is there any way to do this?

I have tried below code to create the custom order status:-

add_filter( 'woocommerce_register_shop_order_post_statuses', 'register_custom_order_status' );

function register_custom_order_status( $order_statuses ){

   // Status must start with "wc-"
   $order_statuses['wc-partialRefunded'] = array(                                 
   'label'                     => _x( 'Partial Refunded', 'Order status', 'woocommerce' ),
   'public'                    => false,                                 
   'exclude_from_search'       => false,                                 
   'show_in_admin_all_list'    => true,                                 
   'show_in_admin_status_list' => true,                                 
   'label_count'               => _n_noop( 'Partial Refunded <span class="count">(%s)</span>', 'Partial Refunded <span class="count">(%s)</span>', 'woocommerce' ),                              
   );      
   return $order_statuses;
}
  1. Show Order Status in the Dropdown @ Single Order and "Bulk Actions" @ Orders
add_filter( 'wc_order_statuses', 'custom_order_status' );


function custom_order_status( $order_statuses ) {      
   $order_statuses['wc-partialRefunded'] = _x( 'Partial Refunded', 'Order status', 'woocommerce' );       
   return $order_statuses;
}

Many Thanks, Sajidul

1

1 Answers

0
votes

This is what I have used to create a custom order status called "Invoiced". Add this to your theme's functions.php

// New order status AFTER woo 2.2

add_action( 'init', 'register_my_new_order_statuses' );

function register_my_new_order_statuses() {
    register_post_status( 'wc-invoiced', array(
        'label'                     => _x( 'Invoiced', '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( 'Invoiced <span class="count">(%s)</span>', 'Invoiced<span class="count">(%s)</span>', 'woocommerce' )
    ) );
}

add_filter( 'wc_order_statuses', 'my_new_wc_order_statuses' );

// Register in wc_order_statuses.
function my_new_wc_order_statuses( $order_statuses ) {
    $order_statuses['wc-invoiced'] = _x( 'Invoiced', 'Order status', 'woocommerce' );

    return $order_statuses;
}

source from :https://wordpress.stackexchange.com/a/199295