/includes/class-wc-post-types.php

  1. <?php 
  2. /** 
  3. * Post Types 
  4. * 
  5. * Registers post types and taxonomies. 
  6. * 
  7. * @class WC_Post_types 
  8. * @version 2.5.0 
  9. * @package WooCommerce/Classes/Products 
  10. * @category Class 
  11. * @author WooThemes 
  12. */ 
  13.  
  14. if ( ! defined( 'ABSPATH' ) ) { 
  15. exit; 
  16.  
  17. /** 
  18. * WC_Post_types Class. 
  19. */ 
  20. class WC_Post_types { 
  21.  
  22. /** 
  23. * Hook in methods. 
  24. */ 
  25. public static function init() { 
  26. add_action( 'init', array( __CLASS__, 'register_taxonomies' ), 5 ); 
  27. add_action( 'init', array( __CLASS__, 'register_post_types' ), 5 ); 
  28. add_action( 'init', array( __CLASS__, 'register_post_status' ), 9 ); 
  29. add_action( 'init', array( __CLASS__, 'support_jetpack_omnisearch' ) ); 
  30. add_filter( 'rest_api_allowed_post_types', array( __CLASS__, 'rest_api_allowed_post_types' ) ); 
  31. add_action( 'woocommerce_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) ); 
  32.  
  33. /** 
  34. * Register core taxonomies. 
  35. */ 
  36. public static function register_taxonomies() { 
  37.  
  38. if ( ! is_blog_installed() ) { 
  39. return; 
  40.  
  41. if ( taxonomy_exists( 'product_type' ) ) { 
  42. return; 
  43.  
  44. do_action( 'woocommerce_register_taxonomy' ); 
  45.  
  46. $permalinks = wc_get_permalink_structure(); 
  47.  
  48. register_taxonomy( 'product_type',  
  49. apply_filters( 'woocommerce_taxonomy_objects_product_type', array( 'product' ) ),  
  50. apply_filters( 'woocommerce_taxonomy_args_product_type', array( 
  51. 'hierarchical' => false,  
  52. 'show_ui' => false,  
  53. 'show_in_nav_menus' => false,  
  54. 'query_var' => is_admin(),  
  55. 'rewrite' => false,  
  56. 'public' => false,  
  57. ) ) 
  58. ); 
  59.  
  60. register_taxonomy( 'product_visibility',  
  61. apply_filters( 'woocommerce_taxonomy_objects_product_visibility', array( 'product', 'product_variation' ) ),  
  62. apply_filters( 'woocommerce_taxonomy_args_product_visibility', array( 
  63. 'hierarchical' => false,  
  64. 'show_ui' => false,  
  65. 'show_in_nav_menus' => false,  
  66. 'query_var' => is_admin(),  
  67. 'rewrite' => false,  
  68. 'public' => false,  
  69. ) ) 
  70. ); 
  71.  
  72. register_taxonomy( 'product_cat',  
  73. apply_filters( 'woocommerce_taxonomy_objects_product_cat', array( 'product' ) ),  
  74. apply_filters( 'woocommerce_taxonomy_args_product_cat', array( 
  75. 'hierarchical' => true,  
  76. 'update_count_callback' => '_wc_term_recount',  
  77. 'label' => __( 'Categories', 'woocommerce' ),  
  78. 'labels' => array( 
  79. 'name' => __( 'Product categories', 'woocommerce' ),  
  80. 'singular_name' => __( 'Category', 'woocommerce' ),  
  81. 'menu_name' => _x( 'Categories', 'Admin menu name', 'woocommerce' ),  
  82. 'search_items' => __( 'Search categories', 'woocommerce' ),  
  83. 'all_items' => __( 'All categories', 'woocommerce' ),  
  84. 'parent_item' => __( 'Parent category', 'woocommerce' ),  
  85. 'parent_item_colon' => __( 'Parent category:', 'woocommerce' ),  
  86. 'edit_item' => __( 'Edit category', 'woocommerce' ),  
  87. 'update_item' => __( 'Update category', 'woocommerce' ),  
  88. 'add_new_item' => __( 'Add new category', 'woocommerce' ),  
  89. 'new_item_name' => __( 'New category name', 'woocommerce' ),  
  90. 'not_found' => __( 'No categories found', 'woocommerce' ),  
  91. ),  
  92. 'show_ui' => true,  
  93. 'query_var' => true,  
  94. 'capabilities' => array( 
  95. 'manage_terms' => 'manage_product_terms',  
  96. 'edit_terms' => 'edit_product_terms',  
  97. 'delete_terms' => 'delete_product_terms',  
  98. 'assign_terms' => 'assign_product_terms',  
  99. ),  
  100. 'rewrite' => array( 
  101. 'slug' => $permalinks['category_rewrite_slug'],  
  102. 'with_front' => false,  
  103. 'hierarchical' => true,  
  104. ),  
  105. ) ) 
  106. ); 
  107.  
  108. register_taxonomy( 'product_tag',  
  109. apply_filters( 'woocommerce_taxonomy_objects_product_tag', array( 'product' ) ),  
  110. apply_filters( 'woocommerce_taxonomy_args_product_tag', array( 
  111. 'hierarchical' => false,  
  112. 'update_count_callback' => '_wc_term_recount',  
  113. 'label' => __( 'Product tags', 'woocommerce' ),  
  114. 'labels' => array( 
  115. 'name' => __( 'Product tags', 'woocommerce' ),  
  116. 'singular_name' => __( 'Tag', 'woocommerce' ),  
  117. 'menu_name' => _x( 'Tags', 'Admin menu name', 'woocommerce' ),  
  118. 'search_items' => __( 'Search tags', 'woocommerce' ),  
  119. 'all_items' => __( 'All tags', 'woocommerce' ),  
  120. 'edit_item' => __( 'Edit tag', 'woocommerce' ),  
  121. 'update_item' => __( 'Update tag', 'woocommerce' ),  
  122. 'add_new_item' => __( 'Add new tag', 'woocommerce' ),  
  123. 'new_item_name' => __( 'New tag name', 'woocommerce' ),  
  124. 'popular_items' => __( 'Popular tags', 'woocommerce' ),  
  125. 'separate_items_with_commas' => __( 'Separate tags with commas', 'woocommerce' ),  
  126. 'add_or_remove_items' => __( 'Add or remove tags', 'woocommerce' ),  
  127. 'choose_from_most_used' => __( 'Choose from the most used tags', 'woocommerce' ),  
  128. 'not_found' => __( 'No tags found', 'woocommerce' ),  
  129. ),  
  130. 'show_ui' => true,  
  131. 'query_var' => true,  
  132. 'capabilities' => array( 
  133. 'manage_terms' => 'manage_product_terms',  
  134. 'edit_terms' => 'edit_product_terms',  
  135. 'delete_terms' => 'delete_product_terms',  
  136. 'assign_terms' => 'assign_product_terms',  
  137. ),  
  138. 'rewrite' => array( 
  139. 'slug' => $permalinks['tag_rewrite_slug'],  
  140. 'with_front' => false,  
  141. ),  
  142. ) ) 
  143. ); 
  144.  
  145. register_taxonomy( 'product_shipping_class',  
  146. apply_filters( 'woocommerce_taxonomy_objects_product_shipping_class', array( 'product', 'product_variation' ) ),  
  147. apply_filters( 'woocommerce_taxonomy_args_product_shipping_class', array( 
  148. 'hierarchical' => false,  
  149. 'update_count_callback' => '_update_post_term_count',  
  150. 'label' => __( 'Shipping classes', 'woocommerce' ),  
  151. 'labels' => array( 
  152. 'name' => __( 'Product shipping classes', 'woocommerce' ),  
  153. 'singular_name' => __( 'Shipping class', 'woocommerce' ),  
  154. 'menu_name' => _x( 'Shipping classes', 'Admin menu name', 'woocommerce' ),  
  155. 'search_items' => __( 'Search shipping classes', 'woocommerce' ),  
  156. 'all_items' => __( 'All shipping classes', 'woocommerce' ),  
  157. 'parent_item' => __( 'Parent shipping class', 'woocommerce' ),  
  158. 'parent_item_colon' => __( 'Parent shipping class:', 'woocommerce' ),  
  159. 'edit_item' => __( 'Edit shipping class', 'woocommerce' ),  
  160. 'update_item' => __( 'Update shipping class', 'woocommerce' ),  
  161. 'add_new_item' => __( 'Add new shipping class', 'woocommerce' ),  
  162. 'new_item_name' => __( 'New shipping class Name', 'woocommerce' ),  
  163. ),  
  164. 'show_ui' => false,  
  165. 'show_in_quick_edit' => false,  
  166. 'show_in_nav_menus' => false,  
  167. 'query_var' => is_admin(),  
  168. 'capabilities' => array( 
  169. 'manage_terms' => 'manage_product_terms',  
  170. 'edit_terms' => 'edit_product_terms',  
  171. 'delete_terms' => 'delete_product_terms',  
  172. 'assign_terms' => 'assign_product_terms',  
  173. ),  
  174. 'rewrite' => false,  
  175. ) ) 
  176. ); 
  177.  
  178. global $wc_product_attributes; 
  179.  
  180. $wc_product_attributes = array(); 
  181.  
  182. if ( $attribute_taxonomies = wc_get_attribute_taxonomies() ) { 
  183. foreach ( $attribute_taxonomies as $tax ) { 
  184. if ( $name = wc_attribute_taxonomy_name( $tax->attribute_name ) ) { 
  185. $tax->attribute_public = absint( isset( $tax->attribute_public ) ? $tax->attribute_public : 1 ); 
  186. $label = ! empty( $tax->attribute_label ) ? $tax->attribute_label : $tax->attribute_name; 
  187. $wc_product_attributes[ $name ] = $tax; 
  188. $taxonomy_data = array( 
  189. 'hierarchical' => false,  
  190. 'update_count_callback' => '_update_post_term_count',  
  191. 'labels' => array( 
  192. 'name' => sprintf( _x( 'Product %s', 'Product Attribute', 'woocommerce' ), $label ),  
  193. 'singular_name' => $label,  
  194. 'search_items' => sprintf( __( 'Search %s', 'woocommerce' ), $label ),  
  195. 'all_items' => sprintf( __( 'All %s', 'woocommerce' ), $label ),  
  196. 'parent_item' => sprintf( __( 'Parent %s', 'woocommerce' ), $label ),  
  197. 'parent_item_colon' => sprintf( __( 'Parent %s:', 'woocommerce' ), $label ),  
  198. 'edit_item' => sprintf( __( 'Edit %s', 'woocommerce' ), $label ),  
  199. 'update_item' => sprintf( __( 'Update %s', 'woocommerce' ), $label ),  
  200. 'add_new_item' => sprintf( __( 'Add new %s', 'woocommerce' ), $label ),  
  201. 'new_item_name' => sprintf( __( 'New %s', 'woocommerce' ), $label ),  
  202. 'not_found' => sprintf( __( 'No "%s" found', 'woocommerce' ), $label ),  
  203. ),  
  204. 'show_ui' => true,  
  205. 'show_in_quick_edit' => false,  
  206. 'show_in_menu' => false,  
  207. 'show_in_nav_menus' => false,  
  208. 'meta_box_cb' => false,  
  209. 'query_var' => 1 === $tax->attribute_public,  
  210. 'rewrite' => false,  
  211. 'sort' => false,  
  212. 'public' => 1 === $tax->attribute_public,  
  213. 'show_in_nav_menus' => 1 === $tax->attribute_public && apply_filters( 'woocommerce_attribute_show_in_nav_menus', false, $name ),  
  214. 'capabilities' => array( 
  215. 'manage_terms' => 'manage_product_terms',  
  216. 'edit_terms' => 'edit_product_terms',  
  217. 'delete_terms' => 'delete_product_terms',  
  218. 'assign_terms' => 'assign_product_terms',  
  219. ),  
  220. ); 
  221.  
  222. if ( 1 === $tax->attribute_public && sanitize_title( $tax->attribute_name ) ) { 
  223. $taxonomy_data['rewrite'] = array( 
  224. 'slug' => trailingslashit( $permalinks['attribute_rewrite_slug'] ) . sanitize_title( $tax->attribute_name ),  
  225. 'with_front' => false,  
  226. 'hierarchical' => true,  
  227. ); 
  228.  
  229. register_taxonomy( $name, apply_filters( "woocommerce_taxonomy_objects_{$name}", array( 'product' ) ), apply_filters( "woocommerce_taxonomy_args_{$name}", $taxonomy_data ) ); 
  230.  
  231. do_action( 'woocommerce_after_register_taxonomy' ); 
  232.  
  233. /** 
  234. * Register core post types. 
  235. */ 
  236. public static function register_post_types() { 
  237. if ( ! is_blog_installed() || post_type_exists( 'product' ) ) { 
  238. return; 
  239.  
  240. do_action( 'woocommerce_register_post_type' ); 
  241.  
  242. $permalinks = wc_get_permalink_structure(); 
  243.  
  244. register_post_type( 'product',  
  245. apply_filters( 'woocommerce_register_post_type_product',  
  246. array( 
  247. 'labels' => array( 
  248. 'name' => __( 'Products', 'woocommerce' ),  
  249. 'singular_name' => __( 'Product', 'woocommerce' ),  
  250. 'menu_name' => _x( 'Products', 'Admin menu name', 'woocommerce' ),  
  251. 'add_new' => __( 'Add product', 'woocommerce' ),  
  252. 'add_new_item' => __( 'Add new product', 'woocommerce' ),  
  253. 'edit' => __( 'Edit', 'woocommerce' ),  
  254. 'edit_item' => __( 'Edit product', 'woocommerce' ),  
  255. 'new_item' => __( 'New product', 'woocommerce' ),  
  256. 'view' => __( 'View product', 'woocommerce' ),  
  257. 'view_item' => __( 'View product', 'woocommerce' ),  
  258. 'search_items' => __( 'Search products', 'woocommerce' ),  
  259. 'not_found' => __( 'No products found', 'woocommerce' ),  
  260. 'not_found_in_trash' => __( 'No products found in trash', 'woocommerce' ),  
  261. 'parent' => __( 'Parent product', 'woocommerce' ),  
  262. 'featured_image' => __( 'Product image', 'woocommerce' ),  
  263. 'set_featured_image' => __( 'Set product image', 'woocommerce' ),  
  264. 'remove_featured_image' => __( 'Remove product image', 'woocommerce' ),  
  265. 'use_featured_image' => __( 'Use as product image', 'woocommerce' ),  
  266. 'insert_into_item' => __( 'Insert into product', 'woocommerce' ),  
  267. 'uploaded_to_this_item' => __( 'Uploaded to this product', 'woocommerce' ),  
  268. 'filter_items_list' => __( 'Filter products', 'woocommerce' ),  
  269. 'items_list_navigation' => __( 'Products navigation', 'woocommerce' ),  
  270. 'items_list' => __( 'Products list', 'woocommerce' ),  
  271. ),  
  272. 'description' => __( 'This is where you can add new products to your store.', 'woocommerce' ),  
  273. 'public' => true,  
  274. 'show_ui' => true,  
  275. 'capability_type' => 'product',  
  276. 'map_meta_cap' => true,  
  277. 'publicly_queryable' => true,  
  278. 'exclude_from_search' => false,  
  279. 'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records! 
  280. 'rewrite' => $permalinks['product_rewrite_slug'] ? array( 'slug' => $permalinks['product_rewrite_slug'], 'with_front' => false, 'feeds' => true ) : false,  
  281. 'query_var' => true,  
  282. 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments', 'custom-fields', 'publicize', 'wpcom-markdown' ),  
  283. 'has_archive' => ( $shop_page_id = wc_get_page_id( 'shop' ) ) && get_post( $shop_page_id ) ? get_page_uri( $shop_page_id ) : 'shop',  
  284. 'show_in_nav_menus' => true,  
  285. 'show_in_rest' => true,  
  286. ); 
  287.  
  288. register_post_type( 'product_variation',  
  289. apply_filters( 'woocommerce_register_post_type_product_variation',  
  290. array( 
  291. 'label' => __( 'Variations', 'woocommerce' ),  
  292. 'public' => false,  
  293. 'hierarchical' => false,  
  294. 'supports' => false,  
  295. 'capability_type' => 'product',  
  296. 'rewrite' => false,  
  297. ); 
  298.  
  299. wc_register_order_type( 
  300. 'shop_order',  
  301. apply_filters( 'woocommerce_register_post_type_shop_order',  
  302. array( 
  303. 'labels' => array( 
  304. 'name' => __( 'Orders', 'woocommerce' ),  
  305. 'singular_name' => _x( 'Order', 'shop_order post type singular name', 'woocommerce' ),  
  306. 'add_new' => __( 'Add order', 'woocommerce' ),  
  307. 'add_new_item' => __( 'Add new order', 'woocommerce' ),  
  308. 'edit' => __( 'Edit', 'woocommerce' ),  
  309. 'edit_item' => __( 'Edit order', 'woocommerce' ),  
  310. 'new_item' => __( 'New order', 'woocommerce' ),  
  311. 'view' => __( 'View order', 'woocommerce' ),  
  312. 'view_item' => __( 'View order', 'woocommerce' ),  
  313. 'search_items' => __( 'Search orders', 'woocommerce' ),  
  314. 'not_found' => __( 'No orders found', 'woocommerce' ),  
  315. 'not_found_in_trash' => __( 'No orders found in trash', 'woocommerce' ),  
  316. 'parent' => __( 'Parent orders', 'woocommerce' ),  
  317. 'menu_name' => _x( 'Orders', 'Admin menu name', 'woocommerce' ),  
  318. 'filter_items_list' => __( 'Filter orders', 'woocommerce' ),  
  319. 'items_list_navigation' => __( 'Orders navigation', 'woocommerce' ),  
  320. 'items_list' => __( 'Orders list', 'woocommerce' ),  
  321. ),  
  322. 'description' => __( 'This is where store orders are stored.', 'woocommerce' ),  
  323. 'public' => false,  
  324. 'show_ui' => true,  
  325. 'capability_type' => 'shop_order',  
  326. 'map_meta_cap' => true,  
  327. 'publicly_queryable' => false,  
  328. 'exclude_from_search' => true,  
  329. 'show_in_menu' => current_user_can( 'manage_woocommerce' ) ? 'woocommerce' : true,  
  330. 'hierarchical' => false,  
  331. 'show_in_nav_menus' => false,  
  332. 'rewrite' => false,  
  333. 'query_var' => false,  
  334. 'supports' => array( 'title', 'comments', 'custom-fields' ),  
  335. 'has_archive' => false,  
  336. ); 
  337.  
  338. wc_register_order_type( 
  339. 'shop_order_refund',  
  340. apply_filters( 'woocommerce_register_post_type_shop_order_refund',  
  341. array( 
  342. 'label' => __( 'Refunds', 'woocommerce' ),  
  343. 'capability_type' => 'shop_order',  
  344. 'public' => false,  
  345. 'hierarchical' => false,  
  346. 'supports' => false,  
  347. 'exclude_from_orders_screen' => false,  
  348. 'add_order_meta_boxes' => false,  
  349. 'exclude_from_order_count' => true,  
  350. 'exclude_from_order_views' => false,  
  351. 'exclude_from_order_reports' => false,  
  352. 'exclude_from_order_sales_reports' => true,  
  353. 'class_name' => 'WC_Order_Refund',  
  354. 'rewrite' => false,  
  355. ); 
  356.  
  357. if ( 'yes' == get_option( 'woocommerce_enable_coupons' ) ) { 
  358. register_post_type( 'shop_coupon',  
  359. apply_filters( 'woocommerce_register_post_type_shop_coupon',  
  360. array( 
  361. 'labels' => array( 
  362. 'name' => __( 'Coupons', 'woocommerce' ),  
  363. 'singular_name' => __( 'Coupon', 'woocommerce' ),  
  364. 'menu_name' => _x( 'Coupons', 'Admin menu name', 'woocommerce' ),  
  365. 'add_new' => __( 'Add coupon', 'woocommerce' ),  
  366. 'add_new_item' => __( 'Add new coupon', 'woocommerce' ),  
  367. 'edit' => __( 'Edit', 'woocommerce' ),  
  368. 'edit_item' => __( 'Edit coupon', 'woocommerce' ),  
  369. 'new_item' => __( 'New coupon', 'woocommerce' ),  
  370. 'view' => __( 'View coupons', 'woocommerce' ),  
  371. 'view_item' => __( 'View coupon', 'woocommerce' ),  
  372. 'search_items' => __( 'Search coupons', 'woocommerce' ),  
  373. 'not_found' => __( 'No coupons found', 'woocommerce' ),  
  374. 'not_found_in_trash' => __( 'No coupons found in trash', 'woocommerce' ),  
  375. 'parent' => __( 'Parent coupon', 'woocommerce' ),  
  376. 'filter_items_list' => __( 'Filter coupons', 'woocommerce' ),  
  377. 'items_list_navigation' => __( 'Coupons navigation', 'woocommerce' ),  
  378. 'items_list' => __( 'Coupons list', 'woocommerce' ),  
  379. ),  
  380. 'description' => __( 'This is where you can add new coupons that customers can use in your store.', 'woocommerce' ),  
  381. 'public' => false,  
  382. 'show_ui' => true,  
  383. 'capability_type' => 'shop_coupon',  
  384. 'map_meta_cap' => true,  
  385. 'publicly_queryable' => false,  
  386. 'exclude_from_search' => true,  
  387. 'show_in_menu' => current_user_can( 'manage_woocommerce' ) ? 'woocommerce' : true,  
  388. 'hierarchical' => false,  
  389. 'rewrite' => false,  
  390. 'query_var' => false,  
  391. 'supports' => array( 'title' ),  
  392. 'show_in_nav_menus' => false,  
  393. 'show_in_admin_bar' => true,  
  394. ); 
  395.  
  396. register_post_type( 'shop_webhook',  
  397. apply_filters( 'woocommerce_register_post_type_shop_webhook',  
  398. array( 
  399. 'labels' => array( 
  400. 'name' => __( 'Webhooks', 'woocommerce' ),  
  401. 'singular_name' => __( 'Webhook', 'woocommerce' ),  
  402. 'menu_name' => _x( 'Webhooks', 'Admin menu name', 'woocommerce' ),  
  403. 'add_new' => __( 'Add webhook', 'woocommerce' ),  
  404. 'add_new_item' => __( 'Add new webhook', 'woocommerce' ),  
  405. 'edit' => __( 'Edit', 'woocommerce' ),  
  406. 'edit_item' => __( 'Edit webhook', 'woocommerce' ),  
  407. 'new_item' => __( 'New webhook', 'woocommerce' ),  
  408. 'view' => __( 'View webhooks', 'woocommerce' ),  
  409. 'view_item' => __( 'View webhook', 'woocommerce' ),  
  410. 'search_items' => __( 'Search webhooks', 'woocommerce' ),  
  411. 'not_found' => __( 'No webhooks found', 'woocommerce' ),  
  412. 'not_found_in_trash' => __( 'No webhooks found in trash', 'woocommerce' ),  
  413. 'parent' => __( 'Parent webhook', 'woocommerce' ),  
  414. ),  
  415. 'public' => false,  
  416. 'show_ui' => true,  
  417. 'capability_type' => 'shop_webhook',  
  418. 'map_meta_cap' => true,  
  419. 'publicly_queryable' => false,  
  420. 'exclude_from_search' => true,  
  421. 'show_in_menu' => false,  
  422. 'hierarchical' => false,  
  423. 'rewrite' => false,  
  424. 'query_var' => false,  
  425. 'supports' => false,  
  426. 'show_in_nav_menus' => false,  
  427. 'show_in_admin_bar' => false,  
  428. ); 
  429.  
  430. do_action( 'woocommerce_after_register_post_type' ); 
  431.  
  432. /** 
  433. * Register our custom post statuses, used for order status. 
  434. */ 
  435. public static function register_post_status() { 
  436.  
  437. $order_statuses = apply_filters( 'woocommerce_register_shop_order_post_statuses',  
  438. array( 
  439. 'wc-pending' => array( 
  440. 'label' => _x( 'Pending payment', 'Order status', 'woocommerce' ),  
  441. 'public' => false,  
  442. 'exclude_from_search' => false,  
  443. 'show_in_admin_all_list' => true,  
  444. 'show_in_admin_status_list' => true,  
  445. 'label_count' => _n_noop( 'Pending payment <span class="count">(%s)</span>', 'Pending payment <span class="count">(%s)</span>', 'woocommerce' ),  
  446. ),  
  447. 'wc-processing' => array( 
  448. 'label' => _x( 'Processing', 'Order status', 'woocommerce' ),  
  449. 'public' => false,  
  450. 'exclude_from_search' => false,  
  451. 'show_in_admin_all_list' => true,  
  452. 'show_in_admin_status_list' => true,  
  453. 'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'woocommerce' ),  
  454. ),  
  455. 'wc-on-hold' => array( 
  456. 'label' => _x( 'On hold', 'Order status', 'woocommerce' ),  
  457. 'public' => false,  
  458. 'exclude_from_search' => false,  
  459. 'show_in_admin_all_list' => true,  
  460. 'show_in_admin_status_list' => true,  
  461. 'label_count' => _n_noop( 'On hold <span class="count">(%s)</span>', 'On hold <span class="count">(%s)</span>', 'woocommerce' ),  
  462. ),  
  463. 'wc-completed' => array( 
  464. 'label' => _x( 'Completed', 'Order status', 'woocommerce' ),  
  465. 'public' => false,  
  466. 'exclude_from_search' => false,  
  467. 'show_in_admin_all_list' => true,  
  468. 'show_in_admin_status_list' => true,  
  469. 'label_count' => _n_noop( 'Completed <span class="count">(%s)</span>', 'Completed <span class="count">(%s)</span>', 'woocommerce' ),  
  470. ),  
  471. 'wc-cancelled' => array( 
  472. 'label' => _x( 'Cancelled', 'Order status', 'woocommerce' ),  
  473. 'public' => false,  
  474. 'exclude_from_search' => false,  
  475. 'show_in_admin_all_list' => true,  
  476. 'show_in_admin_status_list' => true,  
  477. 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'woocommerce' ),  
  478. ),  
  479. 'wc-refunded' => array( 
  480. 'label' => _x( 'Refunded', 'Order status', 'woocommerce' ),  
  481. 'public' => false,  
  482. 'exclude_from_search' => false,  
  483. 'show_in_admin_all_list' => true,  
  484. 'show_in_admin_status_list' => true,  
  485. 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'woocommerce' ),  
  486. ),  
  487. 'wc-failed' => array( 
  488. 'label' => _x( 'Failed', 'Order status', 'woocommerce' ),  
  489. 'public' => false,  
  490. 'exclude_from_search' => false,  
  491. 'show_in_admin_all_list' => true,  
  492. 'show_in_admin_status_list' => true,  
  493. 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'woocommerce' ),  
  494. ),  
  495. ); 
  496.  
  497. foreach ( $order_statuses as $order_status => $values ) { 
  498. register_post_status( $order_status, $values ); 
  499.  
  500. /** 
  501. * Flush rewrite rules. 
  502. */ 
  503. public static function flush_rewrite_rules() { 
  504. flush_rewrite_rules(); 
  505.  
  506. /** 
  507. * Add Product Support to Jetpack Omnisearch. 
  508. */ 
  509. public static function support_jetpack_omnisearch() { 
  510. if ( class_exists( 'Jetpack_Omnisearch_Posts' ) ) { 
  511. new Jetpack_Omnisearch_Posts( 'product' ); 
  512.  
  513. /** 
  514. * Added product for Jetpack related posts. 
  515. * 
  516. * @param array $post_types 
  517. * @return array 
  518. */ 
  519. public static function rest_api_allowed_post_types( $post_types ) { 
  520. $post_types[] = 'product'; 
  521.  
  522. return $post_types; 
  523.  
  524. WC_Post_types::init(); 
.