wc_register_order_type()
Register order type. 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:
- 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.
No Hooks.
Return
true|false
. Success or failure
Usage
wc_register_order_type( $type, $args );
- $type(string) (required)
- Post type. (max. 20 characters, can not contain capital letters or spaces).
- $args(array)
- An array of arguments.
Default: array()
Notes
- See: register_post_type for $args used in that function
Changelog
Since 2.2 | Introduced. |
wc_register_order_type() wc register order type code WC 9.3.3
function wc_register_order_type( $type, $args = array() ) { if ( post_type_exists( $type ) ) { return false; } global $wc_order_types; if ( ! is_array( $wc_order_types ) ) { $wc_order_types = array(); } // Register as a post type. if ( is_wp_error( register_post_type( $type, $args ) ) ) { return false; } // Register for WC usage. $order_type_args = array( 'add_order_meta_boxes' => true, 'exclude_from_order_count' => false, 'exclude_from_order_views' => false, 'exclude_from_order_webhooks' => false, 'exclude_from_order_reports' => false, 'exclude_from_order_sales_reports' => false, 'class_name' => 'WC_Order', ); $args = array_intersect_key( $args, $order_type_args ); $args = wp_parse_args( $args, $order_type_args ); $wc_order_types[ $type ] = $args; return true; }