abstracts
6 years ago
admin
6 years ago
api
6 years ago
blocks
7 years ago
cli
7 years ago
customizer
8 years ago
data-stores
6 years ago
emails
7 years ago
export
7 years ago
gateways
7 years ago
import
7 years ago
interfaces
7 years ago
legacy
7 years ago
libraries
6 years ago
log-handlers
7 years ago
payment-tokens
8 years ago
queue
7 years ago
shipping
7 years ago
shortcodes
6 years ago
theme-support
7 years ago
tracks
6 years ago
walkers
8 years ago
widgets
6 years ago
class-wc-ajax.php
6 years ago
class-wc-api.php
7 years ago
class-wc-auth.php
7 years ago
class-wc-autoloader.php
6 years ago
class-wc-background-emailer.php
8 years ago
class-wc-background-updater.php
7 years ago
class-wc-breadcrumb.php
7 years ago
class-wc-cache-helper.php
7 years ago
class-wc-cart-fees.php
8 years ago
class-wc-cart-session.php
7 years ago
class-wc-cart-totals.php
7 years ago
class-wc-cart.php
7 years ago
class-wc-checkout.php
7 years ago
class-wc-cli.php
8 years ago
class-wc-comments.php
7 years ago
class-wc-countries.php
6 years ago
class-wc-coupon.php
7 years ago
class-wc-customer-download-log.php
8 years ago
class-wc-customer-download.php
8 years ago
class-wc-customer.php
7 years ago
class-wc-data-exception.php
8 years ago
class-wc-data-store.php
7 years ago
class-wc-datetime.php
7 years ago
class-wc-deprecated-action-hooks.php
8 years ago
class-wc-deprecated-filter-hooks.php
7 years ago
class-wc-discounts.php
7 years ago
class-wc-download-handler.php
6 years ago
class-wc-emails.php
7 years ago
class-wc-embed.php
8 years ago
class-wc-form-handler.php
6 years ago
class-wc-frontend-scripts.php
7 years ago
class-wc-geo-ip.php
8 years ago
class-wc-geolite-integration.php
7 years ago
class-wc-geolocation.php
7 years ago
class-wc-https.php
8 years ago
class-wc-install.php
6 years ago
class-wc-integrations.php
8 years ago
class-wc-log-levels.php
7 years ago
class-wc-logger.php
7 years ago
class-wc-meta-data.php
7 years ago
class-wc-order-factory.php
8 years ago
class-wc-order-item-coupon.php
7 years ago
class-wc-order-item-fee.php
7 years ago
class-wc-order-item-meta.php
7 years ago
class-wc-order-item-product.php
7 years ago
class-wc-order-item-shipping.php
7 years ago
class-wc-order-item-tax.php
8 years ago
class-wc-order-item.php
6 years ago
class-wc-order-query.php
7 years ago
class-wc-order-refund.php
8 years ago
class-wc-order.php
7 years ago
class-wc-payment-gateways.php
7 years ago
class-wc-payment-tokens.php
7 years ago
class-wc-post-data.php
7 years ago
class-wc-post-types.php
7 years ago
class-wc-privacy-background-process.php
8 years ago
class-wc-privacy-erasers.php
8 years ago
class-wc-privacy-exporters.php
7 years ago
class-wc-privacy.php
7 years ago
class-wc-product-attribute.php
7 years ago
class-wc-product-download.php
7 years ago
class-wc-product-external.php
8 years ago
class-wc-product-factory.php
7 years ago
class-wc-product-grouped.php
8 years ago
class-wc-product-query.php
7 years ago
class-wc-product-simple.php
8 years ago
class-wc-product-variable.php
7 years ago
class-wc-product-variation.php
7 years ago
class-wc-query.php
7 years ago
class-wc-regenerate-images-request.php
7 years ago
class-wc-regenerate-images.php
7 years ago
class-wc-register-wp-admin-settings.php
8 years ago
class-wc-session-handler.php
7 years ago
class-wc-shipping-rate.php
8 years ago
class-wc-shipping-zone.php
7 years ago
class-wc-shipping-zones.php
8 years ago
class-wc-shipping.php
7 years ago
class-wc-shortcodes.php
7 years ago
class-wc-structured-data.php
6 years ago
class-wc-tax.php
7 years ago
class-wc-template-loader.php
7 years ago
class-wc-tracker.php
6 years ago
class-wc-validation.php
6 years ago
class-wc-webhook.php
7 years ago
class-woocommerce.php
6 years ago
wc-account-functions.php
7 years ago
wc-attribute-functions.php
7 years ago
wc-cart-functions.php
7 years ago
wc-conditional-functions.php
6 years ago
wc-core-functions.php
7 years ago
wc-coupon-functions.php
7 years ago
wc-deprecated-functions.php
7 years ago
wc-formatting-functions.php
6 years ago
wc-notice-functions.php
7 years ago
wc-order-functions.php
7 years ago
wc-order-item-functions.php
7 years ago
wc-page-functions.php
7 years ago
wc-product-functions.php
7 years ago
wc-rest-functions.php
7 years ago
wc-stock-functions.php
7 years ago
wc-template-functions.php
7 years ago
wc-template-hooks.php
7 years ago
wc-term-functions.php
7 years ago
wc-update-functions.php
7 years ago
wc-user-functions.php
7 years ago
wc-webhook-functions.php
7 years ago
wc-widget-functions.php
8 years ago
class-wc-post-types.php
614 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Post Types |
| 4 | * |
| 5 | * Registers post types and taxonomies. |
| 6 | * |
| 7 | * @package WooCommerce/Classes/Products |
| 8 | * @version 2.5.0 |
| 9 | */ |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; |
| 12 | |
| 13 | /** |
| 14 | * Post types Class. |
| 15 | */ |
| 16 | class WC_Post_Types { |
| 17 | |
| 18 | /** |
| 19 | * Hook in methods. |
| 20 | */ |
| 21 | public static function init() { |
| 22 | add_action( 'init', array( __CLASS__, 'register_taxonomies' ), 5 ); |
| 23 | add_action( 'init', array( __CLASS__, 'register_post_types' ), 5 ); |
| 24 | add_action( 'init', array( __CLASS__, 'register_post_status' ), 9 ); |
| 25 | add_action( 'init', array( __CLASS__, 'support_jetpack_omnisearch' ) ); |
| 26 | add_filter( 'rest_api_allowed_post_types', array( __CLASS__, 'rest_api_allowed_post_types' ) ); |
| 27 | add_action( 'woocommerce_after_register_post_type', array( __CLASS__, 'maybe_flush_rewrite_rules' ) ); |
| 28 | add_action( 'woocommerce_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) ); |
| 29 | add_filter( 'gutenberg_can_edit_post_type', array( __CLASS__, 'gutenberg_can_edit_post_type' ), 10, 2 ); |
| 30 | add_filter( 'use_block_editor_for_post_type', array( __CLASS__, 'gutenberg_can_edit_post_type' ), 10, 2 ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Register core taxonomies. |
| 35 | */ |
| 36 | public static function register_taxonomies() { |
| 37 | |
| 38 | if ( ! is_blog_installed() ) { |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | if ( taxonomy_exists( 'product_type' ) ) { |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | do_action( 'woocommerce_register_taxonomy' ); |
| 47 | |
| 48 | $permalinks = wc_get_permalink_structure(); |
| 49 | |
| 50 | register_taxonomy( |
| 51 | 'product_type', |
| 52 | apply_filters( 'woocommerce_taxonomy_objects_product_type', array( 'product' ) ), |
| 53 | apply_filters( |
| 54 | 'woocommerce_taxonomy_args_product_type', |
| 55 | array( |
| 56 | 'hierarchical' => false, |
| 57 | 'show_ui' => false, |
| 58 | 'show_in_nav_menus' => false, |
| 59 | 'query_var' => is_admin(), |
| 60 | 'rewrite' => false, |
| 61 | 'public' => false, |
| 62 | ) |
| 63 | ) |
| 64 | ); |
| 65 | |
| 66 | register_taxonomy( |
| 67 | 'product_visibility', |
| 68 | apply_filters( 'woocommerce_taxonomy_objects_product_visibility', array( 'product', 'product_variation' ) ), |
| 69 | apply_filters( |
| 70 | 'woocommerce_taxonomy_args_product_visibility', |
| 71 | array( |
| 72 | 'hierarchical' => false, |
| 73 | 'show_ui' => false, |
| 74 | 'show_in_nav_menus' => false, |
| 75 | 'query_var' => is_admin(), |
| 76 | 'rewrite' => false, |
| 77 | 'public' => false, |
| 78 | ) |
| 79 | ) |
| 80 | ); |
| 81 | |
| 82 | register_taxonomy( |
| 83 | 'product_cat', |
| 84 | apply_filters( 'woocommerce_taxonomy_objects_product_cat', array( 'product' ) ), |
| 85 | apply_filters( |
| 86 | 'woocommerce_taxonomy_args_product_cat', |
| 87 | array( |
| 88 | 'hierarchical' => true, |
| 89 | 'update_count_callback' => '_wc_term_recount', |
| 90 | 'label' => __( 'Categories', 'woocommerce' ), |
| 91 | 'labels' => array( |
| 92 | 'name' => __( 'Product categories', 'woocommerce' ), |
| 93 | 'singular_name' => __( 'Category', 'woocommerce' ), |
| 94 | 'menu_name' => _x( 'Categories', 'Admin menu name', 'woocommerce' ), |
| 95 | 'search_items' => __( 'Search categories', 'woocommerce' ), |
| 96 | 'all_items' => __( 'All categories', 'woocommerce' ), |
| 97 | 'parent_item' => __( 'Parent category', 'woocommerce' ), |
| 98 | 'parent_item_colon' => __( 'Parent category:', 'woocommerce' ), |
| 99 | 'edit_item' => __( 'Edit category', 'woocommerce' ), |
| 100 | 'update_item' => __( 'Update category', 'woocommerce' ), |
| 101 | 'add_new_item' => __( 'Add new category', 'woocommerce' ), |
| 102 | 'new_item_name' => __( 'New category name', 'woocommerce' ), |
| 103 | 'not_found' => __( 'No categories found', 'woocommerce' ), |
| 104 | ), |
| 105 | 'show_ui' => true, |
| 106 | 'query_var' => true, |
| 107 | 'capabilities' => array( |
| 108 | 'manage_terms' => 'manage_product_terms', |
| 109 | 'edit_terms' => 'edit_product_terms', |
| 110 | 'delete_terms' => 'delete_product_terms', |
| 111 | 'assign_terms' => 'assign_product_terms', |
| 112 | ), |
| 113 | 'rewrite' => array( |
| 114 | 'slug' => $permalinks['category_rewrite_slug'], |
| 115 | 'with_front' => false, |
| 116 | 'hierarchical' => true, |
| 117 | ), |
| 118 | ) |
| 119 | ) |
| 120 | ); |
| 121 | |
| 122 | register_taxonomy( |
| 123 | 'product_tag', |
| 124 | apply_filters( 'woocommerce_taxonomy_objects_product_tag', array( 'product' ) ), |
| 125 | apply_filters( |
| 126 | 'woocommerce_taxonomy_args_product_tag', |
| 127 | array( |
| 128 | 'hierarchical' => false, |
| 129 | 'update_count_callback' => '_wc_term_recount', |
| 130 | 'label' => __( 'Product tags', 'woocommerce' ), |
| 131 | 'labels' => array( |
| 132 | 'name' => __( 'Product tags', 'woocommerce' ), |
| 133 | 'singular_name' => __( 'Tag', 'woocommerce' ), |
| 134 | 'menu_name' => _x( 'Tags', 'Admin menu name', 'woocommerce' ), |
| 135 | 'search_items' => __( 'Search tags', 'woocommerce' ), |
| 136 | 'all_items' => __( 'All tags', 'woocommerce' ), |
| 137 | 'edit_item' => __( 'Edit tag', 'woocommerce' ), |
| 138 | 'update_item' => __( 'Update tag', 'woocommerce' ), |
| 139 | 'add_new_item' => __( 'Add new tag', 'woocommerce' ), |
| 140 | 'new_item_name' => __( 'New tag name', 'woocommerce' ), |
| 141 | 'popular_items' => __( 'Popular tags', 'woocommerce' ), |
| 142 | 'separate_items_with_commas' => __( 'Separate tags with commas', 'woocommerce' ), |
| 143 | 'add_or_remove_items' => __( 'Add or remove tags', 'woocommerce' ), |
| 144 | 'choose_from_most_used' => __( 'Choose from the most used tags', 'woocommerce' ), |
| 145 | 'not_found' => __( 'No tags found', 'woocommerce' ), |
| 146 | ), |
| 147 | 'show_ui' => true, |
| 148 | 'query_var' => true, |
| 149 | 'capabilities' => array( |
| 150 | 'manage_terms' => 'manage_product_terms', |
| 151 | 'edit_terms' => 'edit_product_terms', |
| 152 | 'delete_terms' => 'delete_product_terms', |
| 153 | 'assign_terms' => 'assign_product_terms', |
| 154 | ), |
| 155 | 'rewrite' => array( |
| 156 | 'slug' => $permalinks['tag_rewrite_slug'], |
| 157 | 'with_front' => false, |
| 158 | ), |
| 159 | ) |
| 160 | ) |
| 161 | ); |
| 162 | |
| 163 | register_taxonomy( |
| 164 | 'product_shipping_class', |
| 165 | apply_filters( 'woocommerce_taxonomy_objects_product_shipping_class', array( 'product', 'product_variation' ) ), |
| 166 | apply_filters( |
| 167 | 'woocommerce_taxonomy_args_product_shipping_class', |
| 168 | array( |
| 169 | 'hierarchical' => false, |
| 170 | 'update_count_callback' => '_update_post_term_count', |
| 171 | 'label' => __( 'Shipping classes', 'woocommerce' ), |
| 172 | 'labels' => array( |
| 173 | 'name' => __( 'Product shipping classes', 'woocommerce' ), |
| 174 | 'singular_name' => __( 'Shipping class', 'woocommerce' ), |
| 175 | 'menu_name' => _x( 'Shipping classes', 'Admin menu name', 'woocommerce' ), |
| 176 | 'search_items' => __( 'Search shipping classes', 'woocommerce' ), |
| 177 | 'all_items' => __( 'All shipping classes', 'woocommerce' ), |
| 178 | 'parent_item' => __( 'Parent shipping class', 'woocommerce' ), |
| 179 | 'parent_item_colon' => __( 'Parent shipping class:', 'woocommerce' ), |
| 180 | 'edit_item' => __( 'Edit shipping class', 'woocommerce' ), |
| 181 | 'update_item' => __( 'Update shipping class', 'woocommerce' ), |
| 182 | 'add_new_item' => __( 'Add new shipping class', 'woocommerce' ), |
| 183 | 'new_item_name' => __( 'New shipping class Name', 'woocommerce' ), |
| 184 | ), |
| 185 | 'show_ui' => false, |
| 186 | 'show_in_quick_edit' => false, |
| 187 | 'show_in_nav_menus' => false, |
| 188 | 'query_var' => is_admin(), |
| 189 | 'capabilities' => array( |
| 190 | 'manage_terms' => 'manage_product_terms', |
| 191 | 'edit_terms' => 'edit_product_terms', |
| 192 | 'delete_terms' => 'delete_product_terms', |
| 193 | 'assign_terms' => 'assign_product_terms', |
| 194 | ), |
| 195 | 'rewrite' => false, |
| 196 | ) |
| 197 | ) |
| 198 | ); |
| 199 | |
| 200 | global $wc_product_attributes; |
| 201 | |
| 202 | $wc_product_attributes = array(); |
| 203 | $attribute_taxonomies = wc_get_attribute_taxonomies(); |
| 204 | |
| 205 | if ( $attribute_taxonomies ) { |
| 206 | foreach ( $attribute_taxonomies as $tax ) { |
| 207 | $name = wc_attribute_taxonomy_name( $tax->attribute_name ); |
| 208 | |
| 209 | if ( $name ) { |
| 210 | $tax->attribute_public = absint( isset( $tax->attribute_public ) ? $tax->attribute_public : 1 ); |
| 211 | $label = ! empty( $tax->attribute_label ) ? $tax->attribute_label : $tax->attribute_name; |
| 212 | $wc_product_attributes[ $name ] = $tax; |
| 213 | $taxonomy_data = array( |
| 214 | 'hierarchical' => false, |
| 215 | 'update_count_callback' => '_update_post_term_count', |
| 216 | 'labels' => array( |
| 217 | /* translators: %s: attribute name */ |
| 218 | 'name' => sprintf( _x( 'Product %s', 'Product Attribute', 'woocommerce' ), $label ), |
| 219 | 'singular_name' => $label, |
| 220 | /* translators: %s: attribute name */ |
| 221 | 'search_items' => sprintf( __( 'Search %s', 'woocommerce' ), $label ), |
| 222 | /* translators: %s: attribute name */ |
| 223 | 'all_items' => sprintf( __( 'All %s', 'woocommerce' ), $label ), |
| 224 | /* translators: %s: attribute name */ |
| 225 | 'parent_item' => sprintf( __( 'Parent %s', 'woocommerce' ), $label ), |
| 226 | /* translators: %s: attribute name */ |
| 227 | 'parent_item_colon' => sprintf( __( 'Parent %s:', 'woocommerce' ), $label ), |
| 228 | /* translators: %s: attribute name */ |
| 229 | 'edit_item' => sprintf( __( 'Edit %s', 'woocommerce' ), $label ), |
| 230 | /* translators: %s: attribute name */ |
| 231 | 'update_item' => sprintf( __( 'Update %s', 'woocommerce' ), $label ), |
| 232 | /* translators: %s: attribute name */ |
| 233 | 'add_new_item' => sprintf( __( 'Add new %s', 'woocommerce' ), $label ), |
| 234 | /* translators: %s: attribute name */ |
| 235 | 'new_item_name' => sprintf( __( 'New %s', 'woocommerce' ), $label ), |
| 236 | /* translators: %s: attribute name */ |
| 237 | 'not_found' => sprintf( __( 'No "%s" found', 'woocommerce' ), $label ), |
| 238 | /* translators: %s: attribute name */ |
| 239 | 'back_to_items' => sprintf( __( '← Back to "%s" attributes', 'woocommerce' ), $label ), |
| 240 | ), |
| 241 | 'show_ui' => true, |
| 242 | 'show_in_quick_edit' => false, |
| 243 | 'show_in_menu' => false, |
| 244 | 'meta_box_cb' => false, |
| 245 | 'query_var' => 1 === $tax->attribute_public, |
| 246 | 'rewrite' => false, |
| 247 | 'sort' => false, |
| 248 | 'public' => 1 === $tax->attribute_public, |
| 249 | 'show_in_nav_menus' => 1 === $tax->attribute_public && apply_filters( 'woocommerce_attribute_show_in_nav_menus', false, $name ), |
| 250 | 'capabilities' => array( |
| 251 | 'manage_terms' => 'manage_product_terms', |
| 252 | 'edit_terms' => 'edit_product_terms', |
| 253 | 'delete_terms' => 'delete_product_terms', |
| 254 | 'assign_terms' => 'assign_product_terms', |
| 255 | ), |
| 256 | ); |
| 257 | |
| 258 | if ( 1 === $tax->attribute_public && sanitize_title( $tax->attribute_name ) ) { |
| 259 | $taxonomy_data['rewrite'] = array( |
| 260 | 'slug' => trailingslashit( $permalinks['attribute_rewrite_slug'] ) . sanitize_title( $tax->attribute_name ), |
| 261 | 'with_front' => false, |
| 262 | 'hierarchical' => true, |
| 263 | ); |
| 264 | } |
| 265 | |
| 266 | register_taxonomy( $name, apply_filters( "woocommerce_taxonomy_objects_{$name}", array( 'product' ) ), apply_filters( "woocommerce_taxonomy_args_{$name}", $taxonomy_data ) ); |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | do_action( 'woocommerce_after_register_taxonomy' ); |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Register core post types. |
| 276 | */ |
| 277 | public static function register_post_types() { |
| 278 | if ( ! is_blog_installed() || post_type_exists( 'product' ) ) { |
| 279 | return; |
| 280 | } |
| 281 | |
| 282 | do_action( 'woocommerce_register_post_type' ); |
| 283 | |
| 284 | $permalinks = wc_get_permalink_structure(); |
| 285 | $supports = array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', 'publicize', 'wpcom-markdown' ); |
| 286 | |
| 287 | if ( 'yes' === get_option( 'woocommerce_enable_reviews', 'yes' ) ) { |
| 288 | $supports[] = 'comments'; |
| 289 | } |
| 290 | |
| 291 | $shop_page_id = wc_get_page_id( 'shop' ); |
| 292 | |
| 293 | if ( current_theme_supports( 'woocommerce' ) ) { |
| 294 | $has_archive = $shop_page_id && get_post( $shop_page_id ) ? urldecode( get_page_uri( $shop_page_id ) ) : 'shop'; |
| 295 | } else { |
| 296 | $has_archive = false; |
| 297 | } |
| 298 | |
| 299 | // If theme support changes, we may need to flush permalinks since some are changed based on this flag. |
| 300 | $theme_support = current_theme_supports( 'woocommerce' ) ? 'yes' : 'no'; |
| 301 | if ( get_option( 'current_theme_supports_woocommerce' ) !== $theme_support && update_option( 'current_theme_supports_woocommerce', $theme_support ) ) { |
| 302 | update_option( 'woocommerce_queue_flush_rewrite_rules', 'yes' ); |
| 303 | } |
| 304 | |
| 305 | register_post_type( |
| 306 | 'product', |
| 307 | apply_filters( |
| 308 | 'woocommerce_register_post_type_product', |
| 309 | array( |
| 310 | 'labels' => array( |
| 311 | 'name' => __( 'Products', 'woocommerce' ), |
| 312 | 'singular_name' => __( 'Product', 'woocommerce' ), |
| 313 | 'all_items' => __( 'All Products', 'woocommerce' ), |
| 314 | 'menu_name' => _x( 'Products', 'Admin menu name', 'woocommerce' ), |
| 315 | 'add_new' => __( 'Add New', 'woocommerce' ), |
| 316 | 'add_new_item' => __( 'Add new product', 'woocommerce' ), |
| 317 | 'edit' => __( 'Edit', 'woocommerce' ), |
| 318 | 'edit_item' => __( 'Edit product', 'woocommerce' ), |
| 319 | 'new_item' => __( 'New product', 'woocommerce' ), |
| 320 | 'view_item' => __( 'View product', 'woocommerce' ), |
| 321 | 'view_items' => __( 'View products', 'woocommerce' ), |
| 322 | 'search_items' => __( 'Search products', 'woocommerce' ), |
| 323 | 'not_found' => __( 'No products found', 'woocommerce' ), |
| 324 | 'not_found_in_trash' => __( 'No products found in trash', 'woocommerce' ), |
| 325 | 'parent' => __( 'Parent product', 'woocommerce' ), |
| 326 | 'featured_image' => __( 'Product image', 'woocommerce' ), |
| 327 | 'set_featured_image' => __( 'Set product image', 'woocommerce' ), |
| 328 | 'remove_featured_image' => __( 'Remove product image', 'woocommerce' ), |
| 329 | 'use_featured_image' => __( 'Use as product image', 'woocommerce' ), |
| 330 | 'insert_into_item' => __( 'Insert into product', 'woocommerce' ), |
| 331 | 'uploaded_to_this_item' => __( 'Uploaded to this product', 'woocommerce' ), |
| 332 | 'filter_items_list' => __( 'Filter products', 'woocommerce' ), |
| 333 | 'items_list_navigation' => __( 'Products navigation', 'woocommerce' ), |
| 334 | 'items_list' => __( 'Products list', 'woocommerce' ), |
| 335 | ), |
| 336 | 'description' => __( 'This is where you can add new products to your store.', 'woocommerce' ), |
| 337 | 'public' => true, |
| 338 | 'show_ui' => true, |
| 339 | 'capability_type' => 'product', |
| 340 | 'map_meta_cap' => true, |
| 341 | 'publicly_queryable' => true, |
| 342 | 'exclude_from_search' => false, |
| 343 | 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records! |
| 344 | 'rewrite' => $permalinks['product_rewrite_slug'] ? array( |
| 345 | 'slug' => $permalinks['product_rewrite_slug'], |
| 346 | 'with_front' => false, |
| 347 | 'feeds' => true, |
| 348 | ) : false, |
| 349 | 'query_var' => true, |
| 350 | 'supports' => $supports, |
| 351 | 'has_archive' => $has_archive, |
| 352 | 'show_in_nav_menus' => true, |
| 353 | 'show_in_rest' => true, |
| 354 | ) |
| 355 | ) |
| 356 | ); |
| 357 | |
| 358 | register_post_type( |
| 359 | 'product_variation', |
| 360 | apply_filters( |
| 361 | 'woocommerce_register_post_type_product_variation', |
| 362 | array( |
| 363 | 'label' => __( 'Variations', 'woocommerce' ), |
| 364 | 'public' => false, |
| 365 | 'hierarchical' => false, |
| 366 | 'supports' => false, |
| 367 | 'capability_type' => 'product', |
| 368 | 'rewrite' => false, |
| 369 | ) |
| 370 | ) |
| 371 | ); |
| 372 | |
| 373 | wc_register_order_type( |
| 374 | 'shop_order', |
| 375 | apply_filters( |
| 376 | 'woocommerce_register_post_type_shop_order', |
| 377 | array( |
| 378 | 'labels' => array( |
| 379 | 'name' => __( 'Orders', 'woocommerce' ), |
| 380 | 'singular_name' => _x( 'Order', 'shop_order post type singular name', 'woocommerce' ), |
| 381 | 'add_new' => __( 'Add order', 'woocommerce' ), |
| 382 | 'add_new_item' => __( 'Add new order', 'woocommerce' ), |
| 383 | 'edit' => __( 'Edit', 'woocommerce' ), |
| 384 | 'edit_item' => __( 'Edit order', 'woocommerce' ), |
| 385 | 'new_item' => __( 'New order', 'woocommerce' ), |
| 386 | 'view_item' => __( 'View order', 'woocommerce' ), |
| 387 | 'search_items' => __( 'Search orders', 'woocommerce' ), |
| 388 | 'not_found' => __( 'No orders found', 'woocommerce' ), |
| 389 | 'not_found_in_trash' => __( 'No orders found in trash', 'woocommerce' ), |
| 390 | 'parent' => __( 'Parent orders', 'woocommerce' ), |
| 391 | 'menu_name' => _x( 'Orders', 'Admin menu name', 'woocommerce' ), |
| 392 | 'filter_items_list' => __( 'Filter orders', 'woocommerce' ), |
| 393 | 'items_list_navigation' => __( 'Orders navigation', 'woocommerce' ), |
| 394 | 'items_list' => __( 'Orders list', 'woocommerce' ), |
| 395 | ), |
| 396 | 'description' => __( 'This is where store orders are stored.', 'woocommerce' ), |
| 397 | 'public' => false, |
| 398 | 'show_ui' => true, |
| 399 | 'capability_type' => 'shop_order', |
| 400 | 'map_meta_cap' => true, |
| 401 | 'publicly_queryable' => false, |
| 402 | 'exclude_from_search' => true, |
| 403 | 'show_in_menu' => current_user_can( 'manage_woocommerce' ) ? 'woocommerce' : true, |
| 404 | 'hierarchical' => false, |
| 405 | 'show_in_nav_menus' => false, |
| 406 | 'rewrite' => false, |
| 407 | 'query_var' => false, |
| 408 | 'supports' => array( 'title', 'comments', 'custom-fields' ), |
| 409 | 'has_archive' => false, |
| 410 | ) |
| 411 | ) |
| 412 | ); |
| 413 | |
| 414 | wc_register_order_type( |
| 415 | 'shop_order_refund', |
| 416 | apply_filters( |
| 417 | 'woocommerce_register_post_type_shop_order_refund', |
| 418 | array( |
| 419 | 'label' => __( 'Refunds', 'woocommerce' ), |
| 420 | 'capability_type' => 'shop_order', |
| 421 | 'public' => false, |
| 422 | 'hierarchical' => false, |
| 423 | 'supports' => false, |
| 424 | 'exclude_from_orders_screen' => false, |
| 425 | 'add_order_meta_boxes' => false, |
| 426 | 'exclude_from_order_count' => true, |
| 427 | 'exclude_from_order_views' => false, |
| 428 | 'exclude_from_order_reports' => false, |
| 429 | 'exclude_from_order_sales_reports' => true, |
| 430 | 'class_name' => 'WC_Order_Refund', |
| 431 | 'rewrite' => false, |
| 432 | ) |
| 433 | ) |
| 434 | ); |
| 435 | |
| 436 | if ( 'yes' === get_option( 'woocommerce_enable_coupons' ) ) { |
| 437 | register_post_type( |
| 438 | 'shop_coupon', |
| 439 | apply_filters( |
| 440 | 'woocommerce_register_post_type_shop_coupon', |
| 441 | array( |
| 442 | 'labels' => array( |
| 443 | 'name' => __( 'Coupons', 'woocommerce' ), |
| 444 | 'singular_name' => __( 'Coupon', 'woocommerce' ), |
| 445 | 'menu_name' => _x( 'Coupons', 'Admin menu name', 'woocommerce' ), |
| 446 | 'add_new' => __( 'Add coupon', 'woocommerce' ), |
| 447 | 'add_new_item' => __( 'Add new coupon', 'woocommerce' ), |
| 448 | 'edit' => __( 'Edit', 'woocommerce' ), |
| 449 | 'edit_item' => __( 'Edit coupon', 'woocommerce' ), |
| 450 | 'new_item' => __( 'New coupon', 'woocommerce' ), |
| 451 | 'view_item' => __( 'View coupon', 'woocommerce' ), |
| 452 | 'search_items' => __( 'Search coupons', 'woocommerce' ), |
| 453 | 'not_found' => __( 'No coupons found', 'woocommerce' ), |
| 454 | 'not_found_in_trash' => __( 'No coupons found in trash', 'woocommerce' ), |
| 455 | 'parent' => __( 'Parent coupon', 'woocommerce' ), |
| 456 | 'filter_items_list' => __( 'Filter coupons', 'woocommerce' ), |
| 457 | 'items_list_navigation' => __( 'Coupons navigation', 'woocommerce' ), |
| 458 | 'items_list' => __( 'Coupons list', 'woocommerce' ), |
| 459 | ), |
| 460 | 'description' => __( 'This is where you can add new coupons that customers can use in your store.', 'woocommerce' ), |
| 461 | 'public' => false, |
| 462 | 'show_ui' => true, |
| 463 | 'capability_type' => 'shop_coupon', |
| 464 | 'map_meta_cap' => true, |
| 465 | 'publicly_queryable' => false, |
| 466 | 'exclude_from_search' => true, |
| 467 | 'show_in_menu' => current_user_can( 'manage_woocommerce' ) ? 'woocommerce' : true, |
| 468 | 'hierarchical' => false, |
| 469 | 'rewrite' => false, |
| 470 | 'query_var' => false, |
| 471 | 'supports' => array( 'title' ), |
| 472 | 'show_in_nav_menus' => false, |
| 473 | 'show_in_admin_bar' => true, |
| 474 | ) |
| 475 | ) |
| 476 | ); |
| 477 | } |
| 478 | |
| 479 | do_action( 'woocommerce_after_register_post_type' ); |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * Register our custom post statuses, used for order status. |
| 484 | */ |
| 485 | public static function register_post_status() { |
| 486 | |
| 487 | $order_statuses = apply_filters( |
| 488 | 'woocommerce_register_shop_order_post_statuses', |
| 489 | array( |
| 490 | 'wc-pending' => array( |
| 491 | 'label' => _x( 'Pending payment', 'Order status', 'woocommerce' ), |
| 492 | 'public' => false, |
| 493 | 'exclude_from_search' => false, |
| 494 | 'show_in_admin_all_list' => true, |
| 495 | 'show_in_admin_status_list' => true, |
| 496 | /* translators: %s: number of orders */ |
| 497 | 'label_count' => _n_noop( 'Pending payment <span class="count">(%s)</span>', 'Pending payment <span class="count">(%s)</span>', 'woocommerce' ), |
| 498 | ), |
| 499 | 'wc-processing' => array( |
| 500 | 'label' => _x( 'Processing', 'Order status', 'woocommerce' ), |
| 501 | 'public' => false, |
| 502 | 'exclude_from_search' => false, |
| 503 | 'show_in_admin_all_list' => true, |
| 504 | 'show_in_admin_status_list' => true, |
| 505 | /* translators: %s: number of orders */ |
| 506 | 'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'woocommerce' ), |
| 507 | ), |
| 508 | 'wc-on-hold' => array( |
| 509 | 'label' => _x( 'On hold', 'Order status', 'woocommerce' ), |
| 510 | 'public' => false, |
| 511 | 'exclude_from_search' => false, |
| 512 | 'show_in_admin_all_list' => true, |
| 513 | 'show_in_admin_status_list' => true, |
| 514 | /* translators: %s: number of orders */ |
| 515 | 'label_count' => _n_noop( 'On hold <span class="count">(%s)</span>', 'On hold <span class="count">(%s)</span>', 'woocommerce' ), |
| 516 | ), |
| 517 | 'wc-completed' => array( |
| 518 | 'label' => _x( 'Completed', 'Order status', 'woocommerce' ), |
| 519 | 'public' => false, |
| 520 | 'exclude_from_search' => false, |
| 521 | 'show_in_admin_all_list' => true, |
| 522 | 'show_in_admin_status_list' => true, |
| 523 | /* translators: %s: number of orders */ |
| 524 | 'label_count' => _n_noop( 'Completed <span class="count">(%s)</span>', 'Completed <span class="count">(%s)</span>', 'woocommerce' ), |
| 525 | ), |
| 526 | 'wc-cancelled' => array( |
| 527 | 'label' => _x( 'Cancelled', 'Order status', 'woocommerce' ), |
| 528 | 'public' => false, |
| 529 | 'exclude_from_search' => false, |
| 530 | 'show_in_admin_all_list' => true, |
| 531 | 'show_in_admin_status_list' => true, |
| 532 | /* translators: %s: number of orders */ |
| 533 | 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'woocommerce' ), |
| 534 | ), |
| 535 | 'wc-refunded' => array( |
| 536 | 'label' => _x( 'Refunded', 'Order status', 'woocommerce' ), |
| 537 | 'public' => false, |
| 538 | 'exclude_from_search' => false, |
| 539 | 'show_in_admin_all_list' => true, |
| 540 | 'show_in_admin_status_list' => true, |
| 541 | /* translators: %s: number of orders */ |
| 542 | 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'woocommerce' ), |
| 543 | ), |
| 544 | 'wc-failed' => array( |
| 545 | 'label' => _x( 'Failed', 'Order status', 'woocommerce' ), |
| 546 | 'public' => false, |
| 547 | 'exclude_from_search' => false, |
| 548 | 'show_in_admin_all_list' => true, |
| 549 | 'show_in_admin_status_list' => true, |
| 550 | /* translators: %s: number of orders */ |
| 551 | 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'woocommerce' ), |
| 552 | ), |
| 553 | ) |
| 554 | ); |
| 555 | |
| 556 | foreach ( $order_statuses as $order_status => $values ) { |
| 557 | register_post_status( $order_status, $values ); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * Flush rules if the event is queued. |
| 563 | * |
| 564 | * @since 3.3.0 |
| 565 | */ |
| 566 | public static function maybe_flush_rewrite_rules() { |
| 567 | if ( 'yes' === get_option( 'woocommerce_queue_flush_rewrite_rules' ) ) { |
| 568 | update_option( 'woocommerce_queue_flush_rewrite_rules', 'no' ); |
| 569 | self::flush_rewrite_rules(); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * Flush rewrite rules. |
| 575 | */ |
| 576 | public static function flush_rewrite_rules() { |
| 577 | flush_rewrite_rules(); |
| 578 | } |
| 579 | |
| 580 | /** |
| 581 | * Disable Gutenberg for products. |
| 582 | * |
| 583 | * @param bool $can_edit Whether the post type can be edited or not. |
| 584 | * @param string $post_type The post type being checked. |
| 585 | * @return bool |
| 586 | */ |
| 587 | public static function gutenberg_can_edit_post_type( $can_edit, $post_type ) { |
| 588 | return 'product' === $post_type ? false : $can_edit; |
| 589 | } |
| 590 | |
| 591 | /** |
| 592 | * Add Product Support to Jetpack Omnisearch. |
| 593 | */ |
| 594 | public static function support_jetpack_omnisearch() { |
| 595 | if ( class_exists( 'Jetpack_Omnisearch_Posts' ) ) { |
| 596 | new Jetpack_Omnisearch_Posts( 'product' ); |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | /** |
| 601 | * Added product for Jetpack related posts. |
| 602 | * |
| 603 | * @param array $post_types Post types. |
| 604 | * @return array |
| 605 | */ |
| 606 | public static function rest_api_allowed_post_types( $post_types ) { |
| 607 | $post_types[] = 'product'; |
| 608 | |
| 609 | return $post_types; |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | WC_Post_types::init(); |
| 614 |