2013-06-03 09:45:54 +00:00
|
|
|
<?php
|
2015-02-04 16:14:14 +00:00
|
|
|
/**
|
2015-11-03 13:53:50 +00:00
|
|
|
* Post Types
|
2015-02-04 16:14:14 +00:00
|
|
|
*
|
2015-11-03 13:31:20 +00:00
|
|
|
* Registers post types and taxonomies.
|
2015-02-04 16:14:14 +00:00
|
|
|
*
|
2015-11-11 09:22:43 +00:00
|
|
|
* @class WC_Post_types
|
|
|
|
* @version 2.5.0
|
|
|
|
* @package WooCommerce/Classes/Products
|
|
|
|
* @category Class
|
|
|
|
* @author WooThemes
|
2015-02-04 16:14:14 +00:00
|
|
|
*/
|
2014-05-28 13:52:50 +00:00
|
|
|
|
2014-02-05 15:02:02 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
2015-02-04 16:14:14 +00:00
|
|
|
exit;
|
2014-02-05 15:02:02 +00:00
|
|
|
}
|
2013-06-03 09:45:54 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* WC_Post_types Class.
|
2013-06-03 09:45:54 +00:00
|
|
|
*/
|
|
|
|
class WC_Post_types {
|
|
|
|
|
|
|
|
/**
|
2015-02-04 16:14:14 +00:00
|
|
|
* Hook in methods.
|
2013-06-03 09:45:54 +00:00
|
|
|
*/
|
2014-05-28 13:52:50 +00:00
|
|
|
public static function init() {
|
2014-02-05 15:02:02 +00:00
|
|
|
add_action( 'init', array( __CLASS__, 'register_taxonomies' ), 5 );
|
|
|
|
add_action( 'init', array( __CLASS__, 'register_post_types' ), 5 );
|
2015-02-13 20:08:15 +00:00
|
|
|
add_action( 'init', array( __CLASS__, 'register_post_status' ), 9 );
|
2014-12-26 17:44:38 +00:00
|
|
|
add_action( 'init', array( __CLASS__, 'support_jetpack_omnisearch' ) );
|
2015-08-04 16:49:24 +00:00
|
|
|
add_filter( 'rest_api_allowed_post_types', array( __CLASS__, 'rest_api_allowed_post_types' ) );
|
2017-11-22 11:39:57 +00:00
|
|
|
add_action( 'woocommerce_after_register_post_type', array( __CLASS__, 'maybe_flush_rewrite_rules' ) );
|
2016-10-21 14:29:50 +00:00
|
|
|
add_action( 'woocommerce_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) );
|
2013-06-03 09:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-04 16:14:14 +00:00
|
|
|
* Register core taxonomies.
|
2013-06-03 09:45:54 +00:00
|
|
|
*/
|
2014-02-05 15:02:02 +00:00
|
|
|
public static function register_taxonomies() {
|
2016-11-09 11:53:39 +00:00
|
|
|
|
|
|
|
if ( ! is_blog_installed() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-11 18:38:23 +00:00
|
|
|
if ( taxonomy_exists( 'product_type' ) ) {
|
2013-06-03 09:45:54 +00:00
|
|
|
return;
|
2014-07-11 18:38:23 +00:00
|
|
|
}
|
2013-06-03 09:45:54 +00:00
|
|
|
|
|
|
|
do_action( 'woocommerce_register_taxonomy' );
|
|
|
|
|
2017-02-07 16:16:45 +00:00
|
|
|
$permalinks = wc_get_permalink_structure();
|
2014-02-05 15:02:02 +00:00
|
|
|
|
2013-06-03 09:45:54 +00:00
|
|
|
register_taxonomy( 'product_type',
|
2015-02-04 16:14:14 +00:00
|
|
|
apply_filters( 'woocommerce_taxonomy_objects_product_type', array( 'product' ) ),
|
|
|
|
apply_filters( 'woocommerce_taxonomy_args_product_type', array(
|
|
|
|
'hierarchical' => false,
|
|
|
|
'show_ui' => false,
|
|
|
|
'show_in_nav_menus' => false,
|
|
|
|
'query_var' => is_admin(),
|
|
|
|
'rewrite' => false,
|
2016-08-27 01:46:45 +00:00
|
|
|
'public' => false,
|
2015-02-04 16:14:14 +00:00
|
|
|
) )
|
|
|
|
);
|
2013-06-03 09:45:54 +00:00
|
|
|
|
2016-12-08 10:56:45 +00:00
|
|
|
register_taxonomy( 'product_visibility',
|
|
|
|
apply_filters( 'woocommerce_taxonomy_objects_product_visibility', array( 'product', 'product_variation' ) ),
|
|
|
|
apply_filters( 'woocommerce_taxonomy_args_product_visibility', array(
|
|
|
|
'hierarchical' => false,
|
|
|
|
'show_ui' => false,
|
|
|
|
'show_in_nav_menus' => false,
|
|
|
|
'query_var' => is_admin(),
|
|
|
|
'rewrite' => false,
|
|
|
|
'public' => false,
|
|
|
|
) )
|
|
|
|
);
|
|
|
|
|
2013-06-03 09:45:54 +00:00
|
|
|
register_taxonomy( 'product_cat',
|
2014-07-11 18:38:23 +00:00
|
|
|
apply_filters( 'woocommerce_taxonomy_objects_product_cat', array( 'product' ) ),
|
|
|
|
apply_filters( 'woocommerce_taxonomy_args_product_cat', array(
|
|
|
|
'hierarchical' => true,
|
|
|
|
'update_count_callback' => '_wc_term_recount',
|
2016-07-27 10:47:30 +00:00
|
|
|
'label' => __( 'Categories', 'woocommerce' ),
|
2014-07-11 18:38:23 +00:00
|
|
|
'labels' => array(
|
2016-10-12 10:16:30 +00:00
|
|
|
'name' => __( 'Product categories', 'woocommerce' ),
|
2016-07-27 10:47:30 +00:00
|
|
|
'singular_name' => __( 'Category', 'woocommerce' ),
|
2014-07-11 18:38:23 +00:00
|
|
|
'menu_name' => _x( 'Categories', 'Admin menu name', 'woocommerce' ),
|
2016-10-12 10:16:30 +00:00
|
|
|
'search_items' => __( 'Search categories', 'woocommerce' ),
|
|
|
|
'all_items' => __( 'All categories', 'woocommerce' ),
|
|
|
|
'parent_item' => __( 'Parent category', 'woocommerce' ),
|
|
|
|
'parent_item_colon' => __( 'Parent category:', 'woocommerce' ),
|
|
|
|
'edit_item' => __( 'Edit category', 'woocommerce' ),
|
|
|
|
'update_item' => __( 'Update category', 'woocommerce' ),
|
|
|
|
'add_new_item' => __( 'Add new category', 'woocommerce' ),
|
|
|
|
'new_item_name' => __( 'New category name', 'woocommerce' ),
|
2016-07-27 10:47:30 +00:00
|
|
|
'not_found' => __( 'No categories found', 'woocommerce' ),
|
2014-07-11 18:38:23 +00:00
|
|
|
),
|
|
|
|
'show_ui' => true,
|
|
|
|
'query_var' => true,
|
|
|
|
'capabilities' => array(
|
|
|
|
'manage_terms' => 'manage_product_terms',
|
|
|
|
'edit_terms' => 'edit_product_terms',
|
|
|
|
'delete_terms' => 'delete_product_terms',
|
|
|
|
'assign_terms' => 'assign_product_terms',
|
|
|
|
),
|
2017-02-07 16:16:45 +00:00
|
|
|
'rewrite' => array(
|
|
|
|
'slug' => $permalinks['category_rewrite_slug'],
|
2013-06-03 09:45:54 +00:00
|
|
|
'with_front' => false,
|
|
|
|
'hierarchical' => true,
|
2014-07-11 18:38:23 +00:00
|
|
|
),
|
|
|
|
) )
|
|
|
|
);
|
2013-06-03 09:45:54 +00:00
|
|
|
|
2014-07-11 18:38:23 +00:00
|
|
|
register_taxonomy( 'product_tag',
|
|
|
|
apply_filters( 'woocommerce_taxonomy_objects_product_tag', array( 'product' ) ),
|
|
|
|
apply_filters( 'woocommerce_taxonomy_args_product_tag', array(
|
|
|
|
'hierarchical' => false,
|
|
|
|
'update_count_callback' => '_wc_term_recount',
|
2016-10-12 10:16:30 +00:00
|
|
|
'label' => __( 'Product tags', 'woocommerce' ),
|
2014-07-11 18:38:23 +00:00
|
|
|
'labels' => array(
|
2016-10-12 10:16:30 +00:00
|
|
|
'name' => __( 'Product tags', 'woocommerce' ),
|
2016-07-27 10:47:30 +00:00
|
|
|
'singular_name' => __( 'Tag', 'woocommerce' ),
|
2014-09-12 04:57:43 +00:00
|
|
|
'menu_name' => _x( 'Tags', 'Admin menu name', 'woocommerce' ),
|
2016-10-12 10:16:30 +00:00
|
|
|
'search_items' => __( 'Search tags', 'woocommerce' ),
|
|
|
|
'all_items' => __( 'All tags', 'woocommerce' ),
|
|
|
|
'edit_item' => __( 'Edit tag', 'woocommerce' ),
|
|
|
|
'update_item' => __( 'Update tag', 'woocommerce' ),
|
|
|
|
'add_new_item' => __( 'Add new tag', 'woocommerce' ),
|
|
|
|
'new_item_name' => __( 'New tag name', 'woocommerce' ),
|
|
|
|
'popular_items' => __( 'Popular tags', 'woocommerce' ),
|
|
|
|
'separate_items_with_commas' => __( 'Separate tags with commas', 'woocommerce' ),
|
|
|
|
'add_or_remove_items' => __( 'Add or remove tags', 'woocommerce' ),
|
2016-07-27 10:47:30 +00:00
|
|
|
'choose_from_most_used' => __( 'Choose from the most used tags', 'woocommerce' ),
|
|
|
|
'not_found' => __( 'No tags found', 'woocommerce' ),
|
2014-07-11 18:38:23 +00:00
|
|
|
),
|
|
|
|
'show_ui' => true,
|
|
|
|
'query_var' => true,
|
|
|
|
'capabilities' => array(
|
|
|
|
'manage_terms' => 'manage_product_terms',
|
|
|
|
'edit_terms' => 'edit_product_terms',
|
|
|
|
'delete_terms' => 'delete_product_terms',
|
|
|
|
'assign_terms' => 'assign_product_terms',
|
2013-06-03 09:45:54 +00:00
|
|
|
),
|
2014-07-11 18:38:23 +00:00
|
|
|
'rewrite' => array(
|
2017-02-07 16:16:45 +00:00
|
|
|
'slug' => $permalinks['tag_rewrite_slug'],
|
2016-08-27 01:46:45 +00:00
|
|
|
'with_front' => false,
|
2014-07-11 18:38:23 +00:00
|
|
|
),
|
|
|
|
) )
|
|
|
|
);
|
2013-06-03 09:45:54 +00:00
|
|
|
|
|
|
|
register_taxonomy( 'product_shipping_class',
|
2015-11-11 09:27:31 +00:00
|
|
|
apply_filters( 'woocommerce_taxonomy_objects_product_shipping_class', array( 'product', 'product_variation' ) ),
|
2014-07-11 18:38:23 +00:00
|
|
|
apply_filters( 'woocommerce_taxonomy_args_product_shipping_class', array(
|
2016-03-07 18:19:04 +00:00
|
|
|
'hierarchical' => false,
|
2014-07-11 18:38:23 +00:00
|
|
|
'update_count_callback' => '_update_post_term_count',
|
2016-10-12 10:16:30 +00:00
|
|
|
'label' => __( 'Shipping classes', 'woocommerce' ),
|
2014-07-11 18:38:23 +00:00
|
|
|
'labels' => array(
|
2016-10-12 10:16:30 +00:00
|
|
|
'name' => __( 'Product shipping classes', 'woocommerce' ),
|
|
|
|
'singular_name' => __( 'Shipping class', 'woocommerce' ),
|
|
|
|
'menu_name' => _x( 'Shipping classes', 'Admin menu name', 'woocommerce' ),
|
|
|
|
'search_items' => __( 'Search shipping classes', 'woocommerce' ),
|
|
|
|
'all_items' => __( 'All shipping classes', 'woocommerce' ),
|
|
|
|
'parent_item' => __( 'Parent shipping class', 'woocommerce' ),
|
|
|
|
'parent_item_colon' => __( 'Parent shipping class:', 'woocommerce' ),
|
|
|
|
'edit_item' => __( 'Edit shipping class', 'woocommerce' ),
|
|
|
|
'update_item' => __( 'Update shipping class', 'woocommerce' ),
|
|
|
|
'add_new_item' => __( 'Add new shipping class', 'woocommerce' ),
|
|
|
|
'new_item_name' => __( 'New shipping class Name', 'woocommerce' ),
|
2014-07-11 18:38:23 +00:00
|
|
|
),
|
2016-01-13 16:52:28 +00:00
|
|
|
'show_ui' => false,
|
2015-12-24 12:16:02 +00:00
|
|
|
'show_in_quick_edit' => false,
|
2014-07-11 18:38:23 +00:00
|
|
|
'show_in_nav_menus' => false,
|
|
|
|
'query_var' => is_admin(),
|
|
|
|
'capabilities' => array(
|
|
|
|
'manage_terms' => 'manage_product_terms',
|
|
|
|
'edit_terms' => 'edit_product_terms',
|
|
|
|
'delete_terms' => 'delete_product_terms',
|
|
|
|
'assign_terms' => 'assign_product_terms',
|
2013-06-03 09:45:54 +00:00
|
|
|
),
|
2014-07-11 18:38:23 +00:00
|
|
|
'rewrite' => false,
|
|
|
|
) )
|
|
|
|
);
|
2013-06-03 09:45:54 +00:00
|
|
|
|
2014-07-11 18:38:23 +00:00
|
|
|
global $wc_product_attributes;
|
2013-06-03 09:45:54 +00:00
|
|
|
|
2014-07-11 18:38:23 +00:00
|
|
|
$wc_product_attributes = array();
|
2013-06-03 09:45:54 +00:00
|
|
|
|
2013-09-12 13:41:02 +00:00
|
|
|
if ( $attribute_taxonomies = wc_get_attribute_taxonomies() ) {
|
2013-06-03 09:45:54 +00:00
|
|
|
foreach ( $attribute_taxonomies as $tax ) {
|
2014-07-11 18:38:23 +00:00
|
|
|
if ( $name = wc_attribute_taxonomy_name( $tax->attribute_name ) ) {
|
2015-02-12 00:31:32 +00:00
|
|
|
$tax->attribute_public = absint( isset( $tax->attribute_public ) ? $tax->attribute_public : 1 );
|
2014-12-19 17:58:49 +00:00
|
|
|
$label = ! empty( $tax->attribute_label ) ? $tax->attribute_label : $tax->attribute_name;
|
2014-07-11 18:38:23 +00:00
|
|
|
$wc_product_attributes[ $name ] = $tax;
|
2014-12-19 17:58:49 +00:00
|
|
|
$taxonomy_data = array(
|
2016-12-08 11:23:24 +00:00
|
|
|
'hierarchical' => false,
|
2014-12-19 17:58:49 +00:00
|
|
|
'update_count_callback' => '_update_post_term_count',
|
|
|
|
'labels' => array(
|
2016-10-04 16:53:32 +00:00
|
|
|
'name' => sprintf( _x( 'Product %s', 'Product Attribute', 'woocommerce' ), $label ),
|
2014-12-19 17:58:49 +00:00
|
|
|
'singular_name' => $label,
|
|
|
|
'search_items' => sprintf( __( 'Search %s', 'woocommerce' ), $label ),
|
|
|
|
'all_items' => sprintf( __( 'All %s', 'woocommerce' ), $label ),
|
|
|
|
'parent_item' => sprintf( __( 'Parent %s', 'woocommerce' ), $label ),
|
|
|
|
'parent_item_colon' => sprintf( __( 'Parent %s:', 'woocommerce' ), $label ),
|
|
|
|
'edit_item' => sprintf( __( 'Edit %s', 'woocommerce' ), $label ),
|
|
|
|
'update_item' => sprintf( __( 'Update %s', 'woocommerce' ), $label ),
|
2016-10-12 10:16:30 +00:00
|
|
|
'add_new_item' => sprintf( __( 'Add new %s', 'woocommerce' ), $label ),
|
2016-02-10 17:59:35 +00:00
|
|
|
'new_item_name' => sprintf( __( 'New %s', 'woocommerce' ), $label ),
|
|
|
|
'not_found' => sprintf( __( 'No "%s" found', 'woocommerce' ), $label ),
|
2014-07-11 18:38:23 +00:00
|
|
|
),
|
2015-12-24 12:16:02 +00:00
|
|
|
'show_ui' => true,
|
|
|
|
'show_in_quick_edit' => false,
|
|
|
|
'show_in_menu' => false,
|
|
|
|
'meta_box_cb' => false,
|
|
|
|
'query_var' => 1 === $tax->attribute_public,
|
|
|
|
'rewrite' => false,
|
|
|
|
'sort' => false,
|
|
|
|
'public' => 1 === $tax->attribute_public,
|
|
|
|
'show_in_nav_menus' => 1 === $tax->attribute_public && apply_filters( 'woocommerce_attribute_show_in_nav_menus', false, $name ),
|
|
|
|
'capabilities' => array(
|
2014-12-19 17:58:49 +00:00
|
|
|
'manage_terms' => 'manage_product_terms',
|
|
|
|
'edit_terms' => 'edit_product_terms',
|
|
|
|
'delete_terms' => 'delete_product_terms',
|
|
|
|
'assign_terms' => 'assign_product_terms',
|
2016-08-27 01:46:45 +00:00
|
|
|
),
|
2014-07-11 18:38:23 +00:00
|
|
|
);
|
2014-12-19 17:58:49 +00:00
|
|
|
|
2017-04-06 16:50:04 +00:00
|
|
|
if ( 1 === $tax->attribute_public && sanitize_title( $tax->attribute_name ) ) {
|
2014-12-19 17:58:49 +00:00
|
|
|
$taxonomy_data['rewrite'] = array(
|
2017-02-07 16:16:45 +00:00
|
|
|
'slug' => trailingslashit( $permalinks['attribute_rewrite_slug'] ) . sanitize_title( $tax->attribute_name ),
|
2014-12-19 17:58:49 +00:00
|
|
|
'with_front' => false,
|
2016-08-27 01:46:45 +00:00
|
|
|
'hierarchical' => true,
|
2014-12-19 17:58:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
register_taxonomy( $name, apply_filters( "woocommerce_taxonomy_objects_{$name}", array( 'product' ) ), apply_filters( "woocommerce_taxonomy_args_{$name}", $taxonomy_data ) );
|
2014-07-11 18:38:23 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-03 09:45:54 +00:00
|
|
|
}
|
2015-09-13 07:03:25 +00:00
|
|
|
|
|
|
|
do_action( 'woocommerce_after_register_taxonomy' );
|
2013-06-03 09:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-04 16:14:14 +00:00
|
|
|
* Register core post types.
|
2013-06-03 09:45:54 +00:00
|
|
|
*/
|
2014-02-05 15:02:02 +00:00
|
|
|
public static function register_post_types() {
|
2017-02-07 16:16:45 +00:00
|
|
|
if ( ! is_blog_installed() || post_type_exists( 'product' ) ) {
|
2013-06-03 09:45:54 +00:00
|
|
|
return;
|
2014-07-11 11:43:42 +00:00
|
|
|
}
|
2013-06-03 09:45:54 +00:00
|
|
|
|
|
|
|
do_action( 'woocommerce_register_post_type' );
|
|
|
|
|
2017-02-07 16:16:45 +00:00
|
|
|
$permalinks = wc_get_permalink_structure();
|
2017-06-08 14:26:30 +00:00
|
|
|
$supports = array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', 'publicize', 'wpcom-markdown' );
|
|
|
|
|
|
|
|
if ( 'yes' === get_option( 'woocommerce_enable_reviews', 'yes' ) ) {
|
|
|
|
$supports[] = 'comments';
|
|
|
|
}
|
2013-06-03 09:45:54 +00:00
|
|
|
|
2017-11-08 16:38:12 +00:00
|
|
|
$shop_page_id = wc_get_page_id( 'shop' );
|
2017-11-10 16:32:43 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2017-11-08 16:38:12 +00:00
|
|
|
|
2014-07-11 18:38:23 +00:00
|
|
|
register_post_type( 'product',
|
2013-06-03 09:45:54 +00:00
|
|
|
apply_filters( 'woocommerce_register_post_type_product',
|
|
|
|
array(
|
2014-07-11 18:38:23 +00:00
|
|
|
'labels' => array(
|
2015-07-03 19:57:16 +00:00
|
|
|
'name' => __( 'Products', 'woocommerce' ),
|
|
|
|
'singular_name' => __( 'Product', 'woocommerce' ),
|
2017-04-27 10:39:34 +00:00
|
|
|
'all_items' => __( 'All Products', 'woocommerce' ),
|
2015-07-03 19:57:16 +00:00
|
|
|
'menu_name' => _x( 'Products', 'Admin menu name', 'woocommerce' ),
|
2017-03-22 13:41:21 +00:00
|
|
|
'add_new' => __( 'Add New', 'woocommerce' ),
|
2016-10-12 10:16:30 +00:00
|
|
|
'add_new_item' => __( 'Add new product', 'woocommerce' ),
|
2015-07-03 19:57:16 +00:00
|
|
|
'edit' => __( 'Edit', 'woocommerce' ),
|
2016-10-12 10:16:30 +00:00
|
|
|
'edit_item' => __( 'Edit product', 'woocommerce' ),
|
|
|
|
'new_item' => __( 'New product', 'woocommerce' ),
|
|
|
|
'view' => __( 'View product', 'woocommerce' ),
|
|
|
|
'view_item' => __( 'View product', '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' ),
|
2015-07-03 19:57:16 +00:00
|
|
|
'set_featured_image' => __( 'Set product image', 'woocommerce' ),
|
|
|
|
'remove_featured_image' => __( 'Remove product image', 'woocommerce' ),
|
|
|
|
'use_featured_image' => __( 'Use as product image', 'woocommerce' ),
|
2016-02-17 20:37:36 +00:00
|
|
|
'insert_into_item' => __( 'Insert into product', 'woocommerce' ),
|
|
|
|
'uploaded_to_this_item' => __( 'Uploaded to this product', 'woocommerce' ),
|
2016-02-17 18:40:02 +00:00
|
|
|
'filter_items_list' => __( 'Filter products', 'woocommerce' ),
|
|
|
|
'items_list_navigation' => __( 'Products navigation', 'woocommerce' ),
|
|
|
|
'items_list' => __( 'Products list', 'woocommerce' ),
|
2013-06-03 09:45:54 +00:00
|
|
|
),
|
2014-07-11 18:38:23 +00:00
|
|
|
'description' => __( 'This is where you can add new products to your store.', 'woocommerce' ),
|
|
|
|
'public' => true,
|
|
|
|
'show_ui' => true,
|
|
|
|
'capability_type' => 'product',
|
|
|
|
'map_meta_cap' => true,
|
|
|
|
'publicly_queryable' => true,
|
|
|
|
'exclude_from_search' => false,
|
|
|
|
'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
|
2017-02-07 16:16:45 +00:00
|
|
|
'rewrite' => $permalinks['product_rewrite_slug'] ? array( 'slug' => $permalinks['product_rewrite_slug'], 'with_front' => false, 'feeds' => true ) : false,
|
2014-07-11 18:38:23 +00:00
|
|
|
'query_var' => true,
|
2017-06-08 14:26:30 +00:00
|
|
|
'supports' => $supports,
|
2017-11-08 16:38:12 +00:00
|
|
|
'has_archive' => $has_archive,
|
2016-08-27 01:46:45 +00:00
|
|
|
'show_in_nav_menus' => true,
|
2016-10-12 12:02:07 +00:00
|
|
|
'show_in_rest' => true,
|
2013-06-03 09:45:54 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2014-07-11 18:38:23 +00:00
|
|
|
register_post_type( 'product_variation',
|
2013-06-03 09:45:54 +00:00
|
|
|
apply_filters( 'woocommerce_register_post_type_product_variation',
|
|
|
|
array(
|
2016-12-14 11:28:26 +00:00
|
|
|
'label' => __( 'Variations', 'woocommerce' ),
|
|
|
|
'public' => false,
|
|
|
|
'hierarchical' => false,
|
|
|
|
'supports' => false,
|
2016-08-27 01:46:45 +00:00
|
|
|
'capability_type' => 'product',
|
2016-12-14 11:28:26 +00:00
|
|
|
'rewrite' => false,
|
2013-06-03 09:45:54 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2014-07-11 18:38:23 +00:00
|
|
|
wc_register_order_type(
|
|
|
|
'shop_order',
|
|
|
|
apply_filters( 'woocommerce_register_post_type_shop_order',
|
2013-06-03 09:45:54 +00:00
|
|
|
array(
|
2014-07-11 18:38:23 +00:00
|
|
|
'labels' => array(
|
2016-02-17 16:54:02 +00:00
|
|
|
'name' => __( 'Orders', 'woocommerce' ),
|
|
|
|
'singular_name' => _x( 'Order', 'shop_order post type singular name', 'woocommerce' ),
|
2016-10-12 10:16:30 +00:00
|
|
|
'add_new' => __( 'Add order', 'woocommerce' ),
|
|
|
|
'add_new_item' => __( 'Add new order', 'woocommerce' ),
|
2016-02-17 16:54:02 +00:00
|
|
|
'edit' => __( 'Edit', 'woocommerce' ),
|
2016-10-12 10:16:30 +00:00
|
|
|
'edit_item' => __( 'Edit order', 'woocommerce' ),
|
|
|
|
'new_item' => __( 'New order', 'woocommerce' ),
|
|
|
|
'view' => __( 'View 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' ),
|
2016-02-17 16:54:02 +00:00
|
|
|
'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' ),
|
2013-06-03 09:45:54 +00:00
|
|
|
),
|
2014-07-11 18:38:23 +00:00
|
|
|
'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( 'manage_woocommerce' ) ? 'woocommerce' : true,
|
|
|
|
'hierarchical' => false,
|
|
|
|
'show_in_nav_menus' => false,
|
|
|
|
'rewrite' => false,
|
|
|
|
'query_var' => false,
|
|
|
|
'supports' => array( 'title', 'comments', 'custom-fields' ),
|
|
|
|
'has_archive' => false,
|
2013-06-03 09:45:54 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2014-07-11 18:38:23 +00:00
|
|
|
wc_register_order_type(
|
|
|
|
'shop_order_refund',
|
|
|
|
apply_filters( 'woocommerce_register_post_type_shop_order_refund',
|
2014-07-11 11:43:42 +00:00
|
|
|
array(
|
2014-10-06 12:39:49 +00:00
|
|
|
'label' => __( 'Refunds', 'woocommerce' ),
|
|
|
|
'capability_type' => 'shop_order',
|
|
|
|
'public' => false,
|
|
|
|
'hierarchical' => false,
|
|
|
|
'supports' => false,
|
|
|
|
'exclude_from_orders_screen' => 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,
|
2016-08-27 01:46:45 +00:00
|
|
|
'class_name' => 'WC_Order_Refund',
|
2016-12-14 11:28:26 +00:00
|
|
|
'rewrite' => false,
|
2013-06-03 09:45:54 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2014-07-11 18:38:23 +00:00
|
|
|
if ( 'yes' == get_option( 'woocommerce_enable_coupons' ) ) {
|
|
|
|
register_post_type( 'shop_coupon',
|
|
|
|
apply_filters( 'woocommerce_register_post_type_shop_coupon',
|
2013-08-22 10:58:03 +00:00
|
|
|
array(
|
2014-07-11 18:38:23 +00:00
|
|
|
'labels' => array(
|
2016-02-17 17:16:13 +00:00
|
|
|
'name' => __( 'Coupons', 'woocommerce' ),
|
|
|
|
'singular_name' => __( 'Coupon', 'woocommerce' ),
|
|
|
|
'menu_name' => _x( 'Coupons', 'Admin menu name', 'woocommerce' ),
|
2016-10-12 10:16:30 +00:00
|
|
|
'add_new' => __( 'Add coupon', 'woocommerce' ),
|
|
|
|
'add_new_item' => __( 'Add new coupon', 'woocommerce' ),
|
2016-02-17 17:16:13 +00:00
|
|
|
'edit' => __( 'Edit', 'woocommerce' ),
|
2016-10-12 10:16:30 +00:00
|
|
|
'edit_item' => __( 'Edit coupon', 'woocommerce' ),
|
|
|
|
'new_item' => __( 'New coupon', 'woocommerce' ),
|
|
|
|
'view' => __( 'View coupons', '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' ),
|
2016-02-17 17:16:13 +00:00
|
|
|
'filter_items_list' => __( 'Filter coupons', 'woocommerce' ),
|
|
|
|
'items_list_navigation' => __( 'Coupons navigation', 'woocommerce' ),
|
|
|
|
'items_list' => __( 'Coupons list', 'woocommerce' ),
|
2013-08-22 10:58:03 +00:00
|
|
|
),
|
2014-07-11 18:38:23 +00:00
|
|
|
'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( 'manage_woocommerce' ) ? 'woocommerce' : true,
|
|
|
|
'hierarchical' => false,
|
|
|
|
'rewrite' => false,
|
|
|
|
'query_var' => false,
|
|
|
|
'supports' => array( 'title' ),
|
|
|
|
'show_in_nav_menus' => false,
|
2016-08-27 01:46:45 +00:00
|
|
|
'show_in_admin_bar' => true,
|
2013-08-22 10:58:03 +00:00
|
|
|
)
|
2013-06-03 09:45:54 +00:00
|
|
|
)
|
2013-08-22 10:58:03 +00:00
|
|
|
);
|
2014-02-05 15:02:02 +00:00
|
|
|
}
|
2014-07-30 20:22:40 +00:00
|
|
|
|
2017-03-28 11:37:17 +00:00
|
|
|
do_action( 'woocommerce_after_register_post_type' );
|
2013-06-03 09:45:54 +00:00
|
|
|
}
|
2014-05-30 14:24:53 +00:00
|
|
|
|
|
|
|
/**
|
2015-02-04 16:14:14 +00:00
|
|
|
* Register our custom post statuses, used for order status.
|
2014-05-30 14:24:53 +00:00
|
|
|
*/
|
|
|
|
public static function register_post_status() {
|
2016-04-19 19:20:55 +00:00
|
|
|
|
|
|
|
$order_statuses = apply_filters( 'woocommerce_register_shop_order_post_statuses',
|
|
|
|
array(
|
|
|
|
'wc-pending' => array(
|
2016-10-12 10:16:30 +00:00
|
|
|
'label' => _x( 'Pending payment', 'Order status', 'woocommerce' ),
|
2016-04-19 19:20:55 +00:00
|
|
|
'public' => false,
|
|
|
|
'exclude_from_search' => false,
|
|
|
|
'show_in_admin_all_list' => true,
|
|
|
|
'show_in_admin_status_list' => true,
|
2016-10-12 10:16:30 +00:00
|
|
|
'label_count' => _n_noop( 'Pending payment <span class="count">(%s)</span>', 'Pending payment <span class="count">(%s)</span>', 'woocommerce' ),
|
2016-04-19 19:20:55 +00:00
|
|
|
),
|
|
|
|
'wc-processing' => array(
|
|
|
|
'label' => _x( 'Processing', 'Order status', 'woocommerce' ),
|
|
|
|
'public' => false,
|
|
|
|
'exclude_from_search' => false,
|
|
|
|
'show_in_admin_all_list' => true,
|
|
|
|
'show_in_admin_status_list' => true,
|
2016-08-27 01:46:45 +00:00
|
|
|
'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'woocommerce' ),
|
2016-04-19 19:20:55 +00:00
|
|
|
),
|
|
|
|
'wc-on-hold' => array(
|
2016-10-12 10:16:30 +00:00
|
|
|
'label' => _x( 'On hold', 'Order status', 'woocommerce' ),
|
2016-04-19 19:20:55 +00:00
|
|
|
'public' => false,
|
|
|
|
'exclude_from_search' => false,
|
|
|
|
'show_in_admin_all_list' => true,
|
|
|
|
'show_in_admin_status_list' => true,
|
2016-10-12 10:16:30 +00:00
|
|
|
'label_count' => _n_noop( 'On hold <span class="count">(%s)</span>', 'On hold <span class="count">(%s)</span>', 'woocommerce' ),
|
2016-04-19 19:20:55 +00:00
|
|
|
),
|
|
|
|
'wc-completed' => array(
|
|
|
|
'label' => _x( 'Completed', 'Order status', 'woocommerce' ),
|
|
|
|
'public' => false,
|
|
|
|
'exclude_from_search' => false,
|
|
|
|
'show_in_admin_all_list' => true,
|
|
|
|
'show_in_admin_status_list' => true,
|
2016-08-27 01:46:45 +00:00
|
|
|
'label_count' => _n_noop( 'Completed <span class="count">(%s)</span>', 'Completed <span class="count">(%s)</span>', 'woocommerce' ),
|
2016-04-19 19:20:55 +00:00
|
|
|
),
|
|
|
|
'wc-cancelled' => array(
|
|
|
|
'label' => _x( 'Cancelled', 'Order status', 'woocommerce' ),
|
|
|
|
'public' => false,
|
|
|
|
'exclude_from_search' => false,
|
|
|
|
'show_in_admin_all_list' => true,
|
|
|
|
'show_in_admin_status_list' => true,
|
2016-08-27 01:46:45 +00:00
|
|
|
'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'woocommerce' ),
|
2016-04-19 19:20:55 +00:00
|
|
|
),
|
|
|
|
'wc-refunded' => array(
|
|
|
|
'label' => _x( 'Refunded', 'Order status', 'woocommerce' ),
|
|
|
|
'public' => false,
|
|
|
|
'exclude_from_search' => false,
|
|
|
|
'show_in_admin_all_list' => true,
|
|
|
|
'show_in_admin_status_list' => true,
|
2016-08-27 01:46:45 +00:00
|
|
|
'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'woocommerce' ),
|
2016-04-19 19:20:55 +00:00
|
|
|
),
|
|
|
|
'wc-failed' => array(
|
|
|
|
'label' => _x( 'Failed', 'Order status', 'woocommerce' ),
|
|
|
|
'public' => false,
|
|
|
|
'exclude_from_search' => false,
|
|
|
|
'show_in_admin_all_list' => true,
|
|
|
|
'show_in_admin_status_list' => true,
|
2016-08-27 01:46:45 +00:00
|
|
|
'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'woocommerce' ),
|
2016-04-19 19:20:55 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ( $order_statuses as $order_status => $values ) {
|
|
|
|
register_post_status( $order_status, $values );
|
|
|
|
}
|
2014-05-30 14:24:53 +00:00
|
|
|
}
|
2014-12-26 17:44:38 +00:00
|
|
|
|
2017-11-22 11:39:57 +00:00
|
|
|
/**
|
|
|
|
* Flush rules if the event is queued.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*/
|
|
|
|
public static function maybe_flush_rewrite_rules() {
|
|
|
|
if ( 'true' === get_option( 'woocommerce_queue_flush_rewrite_rules' ) ) {
|
|
|
|
delete_option( 'woocommerce_queue_flush_rewrite_rules' );
|
|
|
|
self::flush_rewrite_rules();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-21 14:29:50 +00:00
|
|
|
/**
|
|
|
|
* Flush rewrite rules.
|
|
|
|
*/
|
|
|
|
public static function flush_rewrite_rules() {
|
|
|
|
flush_rewrite_rules();
|
|
|
|
}
|
|
|
|
|
2014-12-26 17:44:38 +00:00
|
|
|
/**
|
2015-02-04 16:14:14 +00:00
|
|
|
* Add Product Support to Jetpack Omnisearch.
|
|
|
|
*/
|
|
|
|
public static function support_jetpack_omnisearch() {
|
|
|
|
if ( class_exists( 'Jetpack_Omnisearch_Posts' ) ) {
|
|
|
|
new Jetpack_Omnisearch_Posts( 'product' );
|
|
|
|
}
|
|
|
|
}
|
2015-08-03 21:36:25 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Added product for Jetpack related posts.
|
2015-08-03 21:36:25 +00:00
|
|
|
*
|
|
|
|
* @param array $post_types
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function rest_api_allowed_post_types( $post_types ) {
|
|
|
|
$post_types[] = 'product';
|
|
|
|
|
|
|
|
return $post_types;
|
|
|
|
}
|
2013-06-03 09:45:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-28 13:52:50 +00:00
|
|
|
WC_Post_types::init();
|