skip to Main Content

I would like to get all slugs and names of all the WooCommerce order statuses.
I tried the answers from the following thread: Woocommerce get list of order statuses list but with no success.

I use latest woocommerce version. Any help is appreciated.

3

Answers


  1. Add below snippet to functions.php and call woocommerce_get_order_statuses() where you want to use.

    function woocommerce_get_order_statuses() {
          $order_statuses = get_terms( 'shop_order_status', array( 'hide_empty' => false ) );
          $statuses = array();
          foreach ( $order_statuses as $status ) {
            $statuses[ $status->slug ] = $status->name;
          }
          return $statuses;
        }
    
    Login or Signup to reply.
  2. You will use the dedicated function wc_get_order_statuses(), from WC_Order functions, which give you by default the following array:

    $order_statuses = array(
        'wc-pending'    => _x( 'Pending payment', 'Order status', 'woocommerce' ),
        'wc-processing' => _x( 'Processing', 'Order status', 'woocommerce' ),
        'wc-on-hold'    => _x( 'On hold', 'Order status', 'woocommerce' ),
        'wc-completed'  => _x( 'Completed', 'Order status', 'woocommerce' ),
        'wc-cancelled'  => _x( 'Cancelled', 'Order status', 'woocommerce' ),
        'wc-refunded'   => _x( 'Refunded', 'Order status', 'woocommerce' ),
        'wc-failed'     => _x( 'Failed', 'Order status', 'woocommerce' ),
    );
    

    All custom additional order statuses will be included too as the filter hook wc_order_statuses is applied inside this function.

    Login or Signup to reply.
  3. wc_get_order_statuses() will provide only default WooCommerce statuses but to get all order statuses you may use the following function woocommerce_get_all_order_statuses()

    function woocommerce_get_all_order_statuses() {
      $order_statuses = get_posts( array('post_type'=>'wc_order_status', 'post_status'=>'publish', 'numberposts'=>-1) );
     
      $statuses = array();
      foreach ( $order_statuses as $status ) {
        $statuses[ $status->post_name ] = $status->post_title;
      }
    
      return $statuses;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search