WC_Post_Types::register_post_types() – Register core post types.

You appear to be a bot. Output may be restricted

Description

Register core post types.

Usage

WC_Post_Types::register_post_types();

Parameters

Returns

void

Source

File name: woocommerce/includes/class-wc-post-types.php


Lines:

1 to 100 of 208
  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 ( current_theme_supports( 'woocommerce' ) ) {
      $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 = current_theme_supports( 'woocommerce' ) ? '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 add new products to your 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_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(

 View on GitHub View on Trac