wc_register_order_type

Register order type.

Description

wc_register_order_type( (string) $type, (array) $args = array() ); 

Do not use before init.

Wrapper for register post type, as well as a method of telling WC which. post types are types of orders, and having them treated as such.

$args are passed to register_post_type, but there are a few specific to this function: - exclude_from_orders_screen (bool) Whether or not this order type also get shown in the main. orders screen. - add_order_meta_boxes (bool) Whether or not the order type gets shop_order meta boxes. - exclude_from_order_count (bool) Whether or not this order type is excluded from counts. - exclude_from_order_views (bool) Whether or not this order type is visible by customers when. viewing orders e.g. on the my account page. - exclude_from_order_reports (bool) Whether or not to exclude this type from core reports. - exclude_from_order_sales_reports (bool) Whether or not to exclude this type from core sales reports.

Parameters (2)

0. $type (string)
Post type. (max. 20 characters, can not contain capital letters or spaces)
1. $args — Optional. (array) => array()
An array of arguments.

Usage

  1. if ( !function_exists( 'wc_register_order_type' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-order-functions.php'; 
  3.  
  4. // Post type. (max. 20 characters, can not contain capital letters or spaces) 
  5. $type = ''; 
  6.  
  7. // An array of arguments. 
  8. $args = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wc_register_order_type($type, $args); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-order-functions.php  
  1. function wc_register_order_type( $type, $args = array() ) { 
  2. if ( post_type_exists( $type ) ) { 
  3. return false; 
  4.  
  5. global $wc_order_types; 
  6.  
  7. if ( ! is_array( $wc_order_types ) ) { 
  8. $wc_order_types = array(); 
  9.  
  10. // Register as a post type 
  11. if ( is_wp_error( register_post_type( $type, $args ) ) ) { 
  12. return false; 
  13.  
  14. // Register for WC usage 
  15. $order_type_args = array( 
  16. 'exclude_from_orders_screen' => false,  
  17. 'add_order_meta_boxes' => true,  
  18. 'exclude_from_order_count' => false,  
  19. 'exclude_from_order_views' => false,  
  20. 'exclude_from_order_webhooks' => false,  
  21. 'exclude_from_order_reports' => false,  
  22. 'exclude_from_order_sales_reports' => false,  
  23. 'class_name' => 'WC_Order',  
  24. ); 
  25.  
  26. $args = array_intersect_key( $args, $order_type_args ); 
  27. $args = wp_parse_args( $args, $order_type_args ); 
  28. $wc_order_types[ $type ] = $args; 
  29.  
  30. return true;