WC_Post_Types::register_post_types │ public static │ WC 1.0
Register core post types.
Method of the class: WC_Post_Types{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$result = WC_Post_Types::register_post_types();
WC_Post_Types::register_post_types() WC Post Types::register post types code WC 10.3.3
public static function register_post_types() {
if ( ! is_blog_installed() || post_type_exists( 'product' ) ) {
return;
}
do_action( 'woocommerce_register_post_type' );
$permalinks = wc_get_permalink_structure();
$supports = array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', 'publicize', 'wpcom-markdown' );
if ( 'yes' === get_option( 'woocommerce_enable_reviews', 'yes' ) ) {
$supports[] = 'comments';
}
$shop_page_id = wc_get_page_id( 'shop' );
if ( wc_current_theme_supports_woocommerce_or_fse() ) {
$has_archive = $shop_page_id && get_post( $shop_page_id ) ? urldecode( get_page_uri( $shop_page_id ) ) : 'shop';
} else {
$has_archive = false;
}
// If theme support changes, we may need to flush permalinks since some are changed based on this flag.
$theme_support = wc_current_theme_supports_woocommerce_or_fse() ? 'yes' : 'no';
if ( get_option( 'current_theme_supports_woocommerce' ) !== $theme_support && update_option( 'current_theme_supports_woocommerce', $theme_support ) ) {
update_option( 'woocommerce_queue_flush_rewrite_rules', 'yes' );
}
register_post_type(
'product',
apply_filters(
'woocommerce_register_post_type_product',
array(
'labels' => array(
'name' => __( 'Products', 'woocommerce' ),
'singular_name' => __( 'Product', 'woocommerce' ),
'all_items' => __( 'All Products', 'woocommerce' ),
'menu_name' => _x( 'Products', 'Admin menu name', 'woocommerce' ),
'add_new' => __( 'Add New', 'woocommerce' ),
'add_new_item' => __( 'Add new product', 'woocommerce' ),
'edit' => __( 'Edit', 'woocommerce' ),
'edit_item' => __( 'Edit product', 'woocommerce' ),
'new_item' => __( 'New product', 'woocommerce' ),
'view_item' => __( 'View product', 'woocommerce' ),
'view_items' => __( 'View products', 'woocommerce' ),
'search_items' => __( 'Search products', 'woocommerce' ),
'not_found' => __( 'No products found', 'woocommerce' ),
'not_found_in_trash' => __( 'No products found in trash', 'woocommerce' ),
'parent' => __( 'Parent product', 'woocommerce' ),
'featured_image' => __( 'Product image', 'woocommerce' ),
'set_featured_image' => __( 'Set product image', 'woocommerce' ),
'remove_featured_image' => __( 'Remove product image', 'woocommerce' ),
'use_featured_image' => __( 'Use as product image', 'woocommerce' ),
'insert_into_item' => __( 'Insert into product', 'woocommerce' ),
'uploaded_to_this_item' => __( 'Uploaded to this product', 'woocommerce' ),
'filter_items_list' => __( 'Filter products', 'woocommerce' ),
'items_list_navigation' => __( 'Products navigation', 'woocommerce' ),
'items_list' => __( 'Products list', 'woocommerce' ),
'item_link' => __( 'Product Link', 'woocommerce' ),
'item_link_description' => __( 'A link to a product.', 'woocommerce' ),
),
'description' => __( 'This is where you can browse products in this store.', 'woocommerce' ),
'public' => true,
'show_ui' => true,
'menu_icon' => 'dashicons-archive',
'capability_type' => 'product',
'map_meta_cap' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
'rewrite' => $permalinks['product_rewrite_slug'] ? array(
'slug' => $permalinks['product_rewrite_slug'],
'with_front' => false,
'feeds' => true,
) : false,
'query_var' => true,
'supports' => $supports,
'has_archive' => $has_archive,
'show_in_nav_menus' => true,
'show_in_rest' => true,
)
)
);
// Register the product form post type when the feature is enabled.
if ( Features::is_enabled( 'product-editor-template-system' ) ) {
register_post_type(
'product_form',
/**
* Allow developers to customize the product form post type registration arguments.
*
* @since 9.1.0
* @param array $args The default post type registration arguments.
*/
apply_filters(
'woocommerce_register_post_type_product_form',
array(
'labels'
=> array(
'name' => __( 'Product Forms', 'woocommerce' ),
'singular_name' => __( 'Product Form', 'woocommerce' ),
'all_items' => __( 'All Product Form', 'woocommerce' ),
'menu_name' => _x( 'Product Forms', 'Admin menu name', 'woocommerce' ),
'add_new' => __( 'Add New', 'woocommerce' ),
'add_new_item' => __( 'Add new product form', 'woocommerce' ),
'edit' => __( 'Edit', 'woocommerce' ),
'edit_item' => __( 'Edit product form', 'woocommerce' ),
'new_item' => __( 'New product form', 'woocommerce' ),
'view_item' => __( 'View product form', 'woocommerce' ),
'view_items' => __( 'View product forms', 'woocommerce' ),
'search_items' => __( 'Search product forms', 'woocommerce' ),
'not_found' => __( 'No product forms found', 'woocommerce' ),
'not_found_in_trash' => __( 'No product forms found in trash', 'woocommerce' ),
'parent' => __( 'Parent product form', 'woocommerce' ),
'featured_image' => __( 'Product form image', 'woocommerce' ),
'set_featured_image' => __( 'Set product form image', 'woocommerce' ),
'remove_featured_image' => __( 'Remove product form image', 'woocommerce' ),
'use_featured_image' => __( 'Use as product form image', 'woocommerce' ),
'insert_into_item' => __( 'Insert into product form', 'woocommerce' ),
'uploaded_to_this_item' => __( 'Uploaded to this product form', 'woocommerce' ),
'filter_items_list' => __( 'Filter product forms', 'woocommerce' ),
'items_list_navigation' => __( 'Product forms navigation', 'woocommerce' ),
'items_list' => __( 'Product forms list', 'woocommerce' ),
'item_link' => __( 'Product form Link', 'woocommerce' ),
'item_link_description' => __( 'A link to a product form.', 'woocommerce' ),
),
'description' => __( 'This is where you can set up product forms for various product types in your dashboard.', 'woocommerce' ),
'public' => true,
'menu_icon' => 'dashicons-forms',
'capability_type' => 'product',
'map_meta_cap' => true,
'publicly_queryable' => true,
'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
'rewrite' => $permalinks['product_rewrite_slug'] ? array(
'slug' => $permalinks['product_rewrite_slug'],
'with_front' => false,
'feeds' => true,
) : false,
'query_var' => true,
'supports' => $supports,
'has_archive' => $has_archive,
'show_in_rest' => true,
'show_ui' => true,
'show_in_menu' => true,
'exclude_from_search' => true,
'show_in_nav_menus' => false,
)
)
);
}
register_post_type(
'product_variation',
apply_filters(
'woocommerce_register_post_type_product_variation',
array(
'label' => __( 'Variations', 'woocommerce' ),
'public' => false,
'hierarchical' => false,
'supports' => false,
'capability_type' => 'product',
'rewrite' => false,
)
)
);
wc_register_order_type(
'shop_order',
apply_filters(
'woocommerce_register_post_type_shop_order',
array(
'labels' => array(
'name' => __( 'Orders', 'woocommerce' ),
'singular_name' => _x( 'Order', 'shop_order post type singular name', 'woocommerce' ),
'add_new' => __( 'Add order', 'woocommerce' ),
'add_new_item' => __( 'Add new order', 'woocommerce' ),
'edit' => __( 'Edit', 'woocommerce' ),
'edit_item' => __( 'Edit order', 'woocommerce' ),
'new_item' => __( 'New order', 'woocommerce' ),
'view_item' => __( 'View order', 'woocommerce' ),
'search_items' => __( 'Search orders', 'woocommerce' ),
'not_found' => __( 'No orders found', 'woocommerce' ),
'not_found_in_trash' => __( 'No orders found in trash', 'woocommerce' ),
'parent' => __( 'Parent orders', 'woocommerce' ),
'menu_name' => _x( 'Orders', 'Admin menu name', 'woocommerce' ),
'filter_items_list' => __( 'Filter orders', 'woocommerce' ),
'items_list_navigation' => __( 'Orders navigation', 'woocommerce' ),
'items_list' => __( 'Orders list', 'woocommerce' ),
),
'description' => __( 'This is where store orders are stored.', 'woocommerce' ),
'public' => false,
'show_ui' => true,
'capability_type' => 'shop_order',
'map_meta_cap' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
'show_in_menu' => current_user_can( 'edit_others_shop_orders' ) ? 'woocommerce' : true,
'hierarchical' => false,
'show_in_nav_menus' => false,
'rewrite' => false,
'query_var' => false,
'supports' => array( 'title', 'comments', 'custom-fields' ),
'has_archive' => false,
)
)
);
wc_register_order_type(
'shop_order_refund',
apply_filters(
'woocommerce_register_post_type_shop_order_refund',
array(
'label' => __( 'Refunds', 'woocommerce' ),
'capability_type' => 'shop_order',
'public' => false,
'hierarchical' => false,
'supports' => false,
'add_order_meta_boxes' => false,
'exclude_from_order_count' => true,
'exclude_from_order_views' => false,
'exclude_from_order_reports' => false,
'exclude_from_order_sales_reports' => true,
'class_name' => 'WC_Order_Refund',
'rewrite' => false,
)
)
);
if ( 'yes' === get_option( 'woocommerce_enable_coupons' ) ) {
register_post_type(
'shop_coupon',
apply_filters(
'woocommerce_register_post_type_shop_coupon',
array(
'labels' => array(
'name' => __( 'Coupons', 'woocommerce' ),
'singular_name' => __( 'Coupon', 'woocommerce' ),
'menu_name' => _x( 'Coupons', 'Admin menu name', 'woocommerce' ),
'add_new' => __( 'Add coupon', 'woocommerce' ),
'add_new_item' => __( 'Add new coupon', 'woocommerce' ),
'edit' => __( 'Edit', 'woocommerce' ),
'edit_item' => __( 'Edit coupon', 'woocommerce' ),
'new_item' => __( 'New coupon', 'woocommerce' ),
'view_item' => __( 'View coupon', 'woocommerce' ),
'search_items' => __( 'Search coupons', 'woocommerce' ),
'not_found' => __( 'No coupons found', 'woocommerce' ),
'not_found_in_trash' => __( 'No coupons found in trash', 'woocommerce' ),
'parent' => __( 'Parent coupon', 'woocommerce' ),
'filter_items_list' => __( 'Filter coupons', 'woocommerce' ),
'items_list_navigation' => __( 'Coupons navigation', 'woocommerce' ),
'items_list' => __( 'Coupons list', 'woocommerce' ),
),
'description' => __( 'This is where you can add new coupons that customers can use in your store.', 'woocommerce' ),
'public' => false,
'show_ui' => true,
'capability_type' => 'shop_coupon',
'map_meta_cap' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
'show_in_menu' => current_user_can( 'edit_others_shop_orders' ) ? 'woocommerce' : true,
'hierarchical' => false,
'rewrite' => false,
'query_var' => false,
'supports' => array( 'title' ),
'show_in_nav_menus' => false,
'show_in_admin_bar' => true,
)
)
);
}
do_action( 'woocommerce_after_register_post_type' );
}