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

Register order type. Do not use before init.


Description Description

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.

See also See also


Top ↑

Parameters Parameters

$type

(Required) Post type. (max. 20 characters, can not contain capital letters or spaces).

$args

(Optional) An array of arguments.

Default value: array()


Top ↑

Return Return

(bool) Success or failure


Top ↑

Source Source

File: includes/wc-order-functions.php

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(
		'exclude_from_orders_screen'       => false,
		'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;
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.2 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.