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.
Хуков нет.
Возвращает
true|false. Success or failure
Использование
wc_register_order_type( $type, $args );
- $type(строка) (обязательный)
- Post type. (max. 20 characters, can not contain capital letters or spaces).
- $args(массив)
- An array of arguments.
По умолчанию:array()
Заметки
- Смотрите: register_post_type for
$argsused in that function
Список изменений
| С версии 2.2 | Введена. |
Код wc_register_order_type() wc register order type WC 10.9.4
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;
}