Use order types where required

This commit is contained in:
Mike Jolley 2014-07-11 12:43:42 +01:00
parent 2545e55b73
commit 755001f19b
20 changed files with 217 additions and 183 deletions

View File

@ -153,13 +153,13 @@ class WC_Admin_Assets {
wp_localize_script( 'wc-admin-variation-meta-boxes', 'woocommerce_admin_meta_boxes_variations', $params );
}
if ( in_array( $screen->id, array( 'shop_order', 'edit-shop_order' ) ) ) {
if ( in_array( str_replace( 'edit-', '', $screen->id ), wc_get_order_types( 'order-meta-boxes' ) ) ) {
wp_enqueue_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION );
}
if ( in_array( $screen->id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) {
wp_enqueue_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION );
}
if ( in_array( $screen->id, array( 'shop_coupon', 'shop_order', 'product', 'edit-shop_coupon', 'edit-shop_order', 'edit-product' ) ) ) {
if ( in_array( str_replace( 'edit-', '', $screen->id ), array_merge( array( 'shop_coupon', 'product' ), wc_get_order_types( 'order-meta-boxes' ) ) ) ) {
$params = array(
'remove_item_notice' => __( 'Are you sure you want to remove the selected items? If you have previously reduced this item\'s stock, or this order was submitted by a customer, you will need to manually restore the item\'s stock.', 'woocommerce' ),
'i18n_select_items' => __( 'Please select some items.', 'woocommerce' ),

View File

@ -52,7 +52,7 @@ class WC_Admin_Dashboard {
$query = array();
$query['fields'] = "SELECT SUM( postmeta.meta_value ) FROM {$wpdb->posts} as posts";
$query['join'] = "INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id ";
$query['where'] = "WHERE posts.post_type = 'shop_order' ";
$query['where'] = "WHERE posts.post_type IN ( '" . implode( ',', wc_get_order_types( 'reports' ) ) . "' ) ";
$query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) ";
$query['where'] .= "AND postmeta.meta_key = '_order_total' ";
$query['where'] .= "AND posts.post_date >= '" . date( 'Y-m-01', current_time( 'timestamp' ) ) . "' ";
@ -67,7 +67,7 @@ class WC_Admin_Dashboard {
$query['join'] = "INNER JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_id ";
$query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id ";
$query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id ";
$query['where'] = "WHERE posts.post_type = 'shop_order' ";
$query['where'] = "WHERE posts.post_type IN ( '" . implode( ',', wc_get_order_types( 'reports' ) ) . "' ) ";
$query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) ";
$query['where'] .= "AND order_item_meta.meta_key = '_qty' ";
$query['where'] .= "AND order_item_meta_2.meta_key = '_product_id' ";
@ -80,9 +80,14 @@ class WC_Admin_Dashboard {
$top_seller = $wpdb->get_row( implode( ' ', apply_filters( 'woocommerce_dashboard_status_widget_top_seller_query', $query ) ) );
// Counts
$counts = (array) wp_count_posts( 'shop_order' );
$on_hold_count = $counts['wc-on-hold'];
$processing_count = $counts['wc-processing'];
$on_hold_count = 0;
$processing_count = 0;
foreach ( wc_get_order_types( 'order-count' ) as $type ) {
$counts = (array) wp_count_posts( $type );
$on_hold_count += isset( $counts['wc-on-hold'] ) ? $counts['wc-on-hold'] : 0;
$processing_count += isset( $counts['wc-processing'] ? $counts['wc-processing'] : 0;
}
// Get products using a query - this is too advanced for get_posts :(
$stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );

View File

@ -104,12 +104,14 @@ class WC_Admin_Meta_Boxes {
add_meta_box( 'woocommerce-product-images', __( 'Product Gallery', 'woocommerce' ), 'WC_Meta_Box_Product_Images::output', 'product', 'side' );
// Orders
add_meta_box( 'woocommerce-order-data', __( 'Order Data', 'woocommerce' ), 'WC_Meta_Box_Order_Data::output', 'shop_order', 'normal', 'high' );
add_meta_box( 'woocommerce-order-items', __( 'Order Items', 'woocommerce' ), 'WC_Meta_Box_Order_Items::output', 'shop_order', 'normal', 'high' );
add_meta_box( 'woocommerce-order-totals', __( 'Order Totals', 'woocommerce' ), 'WC_Meta_Box_Order_Totals::output', 'shop_order', 'side', 'default' );
add_meta_box( 'woocommerce-order-notes', __( 'Order Notes', 'woocommerce' ), 'WC_Meta_Box_Order_Notes::output', 'shop_order', 'side', 'default' );
add_meta_box( 'woocommerce-order-downloads', __( 'Downloadable Product Permissions', 'woocommerce' ) . ' <span class="tips" data-tip="' . __( 'Note: Permissions for order items will automatically be granted when the order status changes to processing/completed.', 'woocommerce' ) . '">[?]</span>', 'WC_Meta_Box_Order_Downloads::output', 'shop_order', 'normal', 'default' );
add_meta_box( 'woocommerce-order-actions', __( 'Order Actions', 'woocommerce' ), 'WC_Meta_Box_Order_Actions::output', 'shop_order', 'side', 'high' );
foreach ( wc_get_order_types( 'order-meta-boxes' ) as $type ) {
add_meta_box( 'woocommerce-order-data', __( 'Order Data', 'woocommerce' ), 'WC_Meta_Box_Order_Data::output', $type, 'normal', 'high' );
add_meta_box( 'woocommerce-order-items', __( 'Order Items', 'woocommerce' ), 'WC_Meta_Box_Order_Items::output', $type, 'normal', 'high' );
add_meta_box( 'woocommerce-order-totals', __( 'Order Totals', 'woocommerce' ), 'WC_Meta_Box_Order_Totals::output', $type, 'side', 'default' );
add_meta_box( 'woocommerce-order-notes', __( 'Order Notes', 'woocommerce' ), 'WC_Meta_Box_Order_Notes::output', $type, 'side', 'default' );
add_meta_box( 'woocommerce-order-downloads', __( 'Downloadable Product Permissions', 'woocommerce' ) . ' <span class="tips" data-tip="' . __( 'Note: Permissions for order items will automatically be granted when the order status changes to processing/completed.', 'woocommerce' ) . '">[?]</span>', 'WC_Meta_Box_Order_Downloads::output', $type, 'normal', 'default' );
add_meta_box( 'woocommerce-order-actions', __( 'Order Actions', 'woocommerce' ), 'WC_Meta_Box_Order_Actions::output', $type, 'side', 'high' );
}
// Coupons
add_meta_box( 'woocommerce-coupon-data', __( 'Coupon Data', 'woocommerce' ), 'WC_Meta_Box_Coupon_Data::output', 'shop_coupon', 'normal', 'high' );
@ -134,10 +136,13 @@ class WC_Admin_Meta_Boxes {
remove_meta_box( 'woothemes-settings', 'shop_coupon' , 'normal' );
remove_meta_box( 'commentstatusdiv', 'shop_coupon' , 'normal' );
remove_meta_box( 'slugdiv', 'shop_coupon' , 'normal' );
remove_meta_box( 'commentsdiv', 'shop_order' , 'normal' );
remove_meta_box( 'woothemes-settings', 'shop_order' , 'normal' );
remove_meta_box( 'commentstatusdiv', 'shop_order' , 'normal' );
remove_meta_box( 'slugdiv', 'shop_order' , 'normal' );
foreach ( wc_get_order_types( 'order-meta-boxes' ) as $type ) {
remove_meta_box( 'commentsdiv', $type, 'normal' );
remove_meta_box( 'woothemes-settings', $type, 'normal' );
remove_meta_box( 'commentstatusdiv', $type, 'normal' );
remove_meta_box( 'slugdiv', $type, 'normal' );
}
}
/**
@ -187,11 +192,11 @@ class WC_Admin_Meta_Boxes {
}
// Check the post type
if ( ! in_array( $post->post_type, array( 'product', 'shop_order', 'shop_coupon' ) ) ) {
return;
if ( in_array( $post->post_type, wc_get_order_types( 'order-meta-boxes' ) ) ) {
do_action( 'woocommerce_process_shop_order_meta', $post_id, $post );
} elseif ( in_array( $post->post_type, array( 'product', 'shop_coupon' ) ) ) {
do_action( 'woocommerce_process_' . $post->post_type . '_meta', $post_id, $post );
}
do_action( 'woocommerce_process_' . $post->post_type . '_meta', $post_id, $post );
}
}

View File

@ -1524,6 +1524,7 @@ class WC_Admin_Post_Types {
}
} elseif ( 'shop_order' === $typenow ) {
// Filter the orders by the posted customer.
if ( isset( $_GET['_customer_user'] ) && $_GET['_customer_user'] > 0 ) {
$vars['meta_key'] = '_customer_user';

View File

@ -128,7 +128,7 @@ class WC_Admin_Report {
$query['join'] = implode( ' ', $joins );
$query['where'] = "
WHERE posts.post_type = 'shop_order'
WHERE posts.post_type IN ( '" . implode( ',', wc_get_order_types( 'reports' ) ) . "' )
AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "')
";

View File

@ -116,7 +116,7 @@ class WC_Report_Customer_List extends WP_List_Table {
WHERE meta.meta_key = '_customer_user'
AND meta.meta_value = $user->ID
AND posts.post_type = 'shop_order'
AND posts.post_type IN ('" . implode( ',', wc_get_order_types( 'reports' ) ) . "')
AND posts.post_status = 'wc-completed'
AND meta2.meta_key = '_order_total'
" );
@ -135,7 +135,7 @@ class WC_Report_Customer_List extends WP_List_Table {
LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id
WHERE meta.meta_key = '_customer_user'
AND posts.post_type = 'shop_order'
AND posts.post_type IN ('" . implode( ',', wc_get_order_types( 'order-count' ) ) . "')
AND posts.post_status = 'wc-completed'
AND meta_value = $user->ID
" );
@ -190,7 +190,7 @@ class WC_Report_Customer_List extends WP_List_Table {
$order_ids = get_posts( array(
'posts_per_page' => 1,
'post_type' => 'shop_order',
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_order_statuses() ),
'meta_query' => array(
array(

View File

@ -17,16 +17,13 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
*/
function wc_get_screen_ids() {
$wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) );
return apply_filters( 'woocommerce_screen_ids', array(
$screen_ids = array(
'toplevel_page_' . $wc_screen_id,
$wc_screen_id . '_page_wc-reports',
$wc_screen_id . '_page_wc-settings',
$wc_screen_id . '_page_wc-status',
$wc_screen_id . '_page_wc-addons',
'product_page_product_attributes',
'edit-shop_order',
'shop_order',
'edit-product',
'product',
'edit-shop_coupon',
@ -34,7 +31,14 @@ function wc_get_screen_ids() {
'edit-product_cat',
'edit-product_tag',
'edit-product_shipping_class'
) );
);
foreach ( wc_get_order_types() as $type ) {
$screen_ids[] = $type;
$screen_ids[] = 'edit-' . $type;
}
return apply_filters( 'woocommerce_screen_ids', $screen_ids );
}
/**

View File

@ -1696,7 +1696,7 @@ class WC_AJAX {
$refund_id = absint( $_POST['refund_id'] );
if ( $refund_id && 'shop_order' === get_post_type( $refund_id ) ) {
if ( $refund_id && 'shop_order_refund' === get_post_type( $refund_id ) ) {
wp_delete_post( $refund_id );
}

View File

@ -481,7 +481,7 @@ class WC_Cart {
WHERE order_item_meta.meta_key = '_qty'
AND order_item_meta2.meta_key = %s AND order_item_meta2.meta_value = %d
AND posts.post_type = 'shop_order'
AND posts.post_type IN ( '" . implode( ',', wc_get_order_types() ) . "' )
AND posts.post_status = 'wc-pending'
AND posts.ID != %d
", $key, $value, $order_id ) );

View File

@ -178,7 +178,7 @@ class WC_Checkout {
$order_id = absint( WC()->session->order_awaiting_payment );
// Resume the unpaid order if its pending
if ( $order_id > 0 && ( $order = new WC_Order( $order_id ) ) && $order->has_status( array( 'pending', 'failed' ) ) ) {
if ( $order_id > 0 && ( $order = get_order( $order_id ) ) && $order->has_status( array( 'pending', 'failed' ) ) ) {
$order_data['order_id'] = $order_id;
$order = wc_update_order( $order_data );

View File

@ -49,7 +49,7 @@ class WC_Comments {
public static function exclude_order_comments( $clauses ) {
global $wpdb, $typenow;
if ( is_admin() && $typenow == 'shop_order' && current_user_can( 'manage_woocommerce' ) )
if ( is_admin() && in_array( $typenow, wc_get_order_types() ) && current_user_can( 'manage_woocommerce' ) )
return $clauses; // Don't hide when viewing orders in admin
if ( ! $clauses['join'] )
@ -61,7 +61,7 @@ class WC_Comments {
if ( $clauses['where'] )
$clauses['where'] .= ' AND ';
$clauses['where'] .= " $wpdb->posts.post_type NOT IN ('shop_order') ";
$clauses['where'] .= " $wpdb->posts.post_type NOT IN ('" . implode( ',', wc_get_order_types() ) . "') ";
return $clauses;
}
@ -93,7 +93,7 @@ class WC_Comments {
if ( $where )
$where .= ' AND ';
$where .= " $wpdb->posts.post_type NOT IN ('shop_order') ";
$where .= " $wpdb->posts.post_type NOT IN ('" . implode( ',', wc_get_order_types() ) . "') ";
return $where;
}

View File

@ -37,25 +37,14 @@ class WC_Order_Factory {
$order_id = absint( $the_order->ID );
$post_type = $the_order->post_type;
if ( 'shop_order' == $post_type ) {
$terms = get_the_terms( $order_id, 'order_type' );
$order_type = ! empty( $terms ) && isset( current( $terms )->name ) ? sanitize_title( current( $terms )->name ) : 'simple';
// Create a WC coding standards compliant class name e.g. WC_Order_Type_Class instead of WC_order_type-class
$classname = 'WC_Order_' . implode( '_', array_map( 'ucfirst', explode( '-', $order_type ) ) );
// The default order class must be WC_Order to provide backwards compatibility
if ( 'WC_Order_Simple' ) {
$classname = 'WC_Order';
}
if ( $order_type = wc_get_order_type( $post_type ) ) {
$classname = $order_type['class_name'];
} else {
$classname = false;
$order_type = false;
}
// Filter classname so that the class can be overridden if extended.
$classname = apply_filters( 'woocommerce_order_class', $classname, $order_type, $post_type, $order_id );
$classname = apply_filters( 'woocommerce_order_class', $classname, $post_type, $order_id );
if ( ! class_exists( $classname ) ) {
$classname = 'WC_Order';

View File

@ -34,17 +34,10 @@ class WC_Order extends WC_Abstract_Order {
$refunds = array();
$refund_items = get_posts(
array(
'post_type' => 'shop_order',
'post_type' => 'shop_order_refund',
'post_parent' => $this->id,
'posts_per_page' => -1,
'fields' => 'ids',
'tax_query' => array(
array(
'taxonomy' => 'order_type',
'terms' => 'refund',
'field' => 'slug'
)
)
'fields' => 'ids'
)
);
@ -67,10 +60,7 @@ class WC_Order extends WC_Abstract_Order {
$total = $wpdb->get_var( $wpdb->prepare( "
SELECT SUM( postmeta.meta_value )
FROM $wpdb->postmeta AS postmeta
INNER JOIN $wpdb->posts AS posts ON ( posts.post_type = 'shop_order' AND posts.post_parent = %d )
INNER JOIN $wpdb->term_relationships AS term_relationships ON ( posts.ID = term_relationships.object_id )
INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON( term_relationships.term_taxonomy_id = term_taxonomy.term_taxonomy_id AND term_taxonomy.taxonomy = 'order_type' )
INNER JOIN $wpdb->terms AS terms ON( term_taxonomy.term_id = terms.term_id AND terms.name = 'refund' )
INNER JOIN $wpdb->posts AS posts ON ( posts.post_type = 'shop_order_refund' AND posts.post_parent = %d )
WHERE postmeta.meta_key = '_refund_amount'
GROUP BY posts.ID
", $this->id ) );

View File

@ -146,7 +146,7 @@ class WC_Post_Data {
* @return null|bool
*/
public static function update_post_metadata( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
if ( ! empty( $meta_value ) && is_float( $meta_value ) && in_array( get_post_type( $object_id ), array( 'shop_order', 'shop_coupon', 'product', 'product_variation' ) ) ) {
if ( ! empty( $meta_value ) && is_float( $meta_value ) && in_array( get_post_type( $object_id ), array_merge( wc_get_order_types(), array( 'shop_coupon', 'product', 'product_variation' ) ) ) ) {
// Convert float to string
$meta_value = wc_float_to_string( $meta_value );

View File

@ -37,18 +37,6 @@ class WC_Post_types {
$permalinks = get_option( 'woocommerce_permalinks' );
register_taxonomy( 'order_type',
apply_filters( 'woocommerce_taxonomy_objects_order_type', array( 'shop_order' ) ),
apply_filters( 'woocommerce_taxonomy_args_order_type', array(
'hierarchical' => false,
'show_ui' => false,
'show_in_nav_menus' => false,
'query_var' => is_admin(),
'rewrite' => false,
'public' => false
) )
);
register_taxonomy( 'product_type',
apply_filters( 'woocommerce_taxonomy_objects_product_type', array( 'product' ) ),
apply_filters( 'woocommerce_taxonomy_args_product_type', array(
@ -218,8 +206,9 @@ class WC_Post_types {
* Register core post types
*/
public static function register_post_types() {
if ( post_type_exists('product') )
if ( post_type_exists('product') ) {
return;
}
do_action( 'woocommerce_register_post_type' );
@ -321,6 +310,24 @@ class WC_Post_types {
)
);
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,
'exclude_from_orders_screen' => false,
'add_order_meta_boxes' => false,
'exclude_from_order_count' => true,
'exclude_from_order_views' => false,
'class_name' => 'WC_Order_Refund'
)
)
);
if ( get_option( 'woocommerce_enable_coupons' ) == 'yes' ) {
register_post_type( "shop_coupon",
apply_filters( 'woocommerce_register_post_type_shop_coupon',

View File

@ -108,9 +108,6 @@ function wc_create_order( $args = array() ) {
update_post_meta( $order_id, '_customer_user', $args['customer_id'] );
}
// Set the order type.
wp_set_object_terms( $order_id, 'simple', 'order_type' );
return new WC_Order( $order_id );
}

View File

@ -68,6 +68,132 @@ function wc_get_order_id_by_order_key( $order_key ) {
return $order_id;
}
/**
* Get all registered order types
*
* $for optionally define what you are getting order types for so only relevent types are returned.
*
* e.g. for 'order-meta-boxes', 'order-count'
*
* @since 2.2
* @param string $for
* @return array
*/
function wc_get_order_types( $for = '' ) {
global $wc_order_types;
if ( ! is_array( $wc_order_types ) ) {
$wc_order_types = array();
}
$order_types = array();
switch ( $for ) {
case 'order-count' :
foreach ( $wc_order_types as $type => $args ) {
if ( ! $args['exclude_from_order_count'] ) {
$order_types[] = $type;
}
}
break;
case 'order-meta-boxes' :
foreach ( $wc_order_types as $type => $args ) {
if ( $args['add_order_meta_boxes'] ) {
$order_types[] = $type;
}
}
break;
case 'view-orders' :
foreach ( $wc_order_types as $type => $args ) {
if ( ! $args['exclude_from_order_views'] ) {
$order_types[] = $type;
}
}
break;
case 'reports' :
foreach ( $wc_order_types as $type => $args ) {
if ( ! $args['exclude_from_order_reports'] ) {
$order_types[] = $type;
}
}
break;
default :
$order_types = array_keys( $wc_order_types );
break;
}
return apply_filters( 'wc_order_types', $order_types, $for );
}
/**
* Get an order type by post type name
* @param string post type name
* @return bool|array of datails about the order type
*/
function wc_get_order_type( $type ) {
global $wc_order_types;
if ( isset( $wc_order_types[ $type ] ) ) {
return $wc_order_types[ $type ];
} else {
return false;
}
}
/**
* Register order type
*
* Wrapper for register post type, as well as a method of telling WC which
* post types are types of orders, and having them treated as such.
*
* $args are passed to register_post_type, but there are a few specific to this function:
* - exclude_from_orders_screen (bool) Whether or not this order type also get shown in the main
* orders screen.
* - add_order_meta_boxes (bool) Whether or not the order type gets shop_order meta boxes.
* - exclude_from_order_count (bool) Whether or not this order type is excluded from counts.
* - exclude_from_order_views (bool) Whether or not this order type is visible by customers when
* viewing orders e.g. on the my account page.
* - exclude_from_order_reports (bool) Whether or not to exclude this type from core reports.
*
* @since 2.2
* @see register_post_type for $args used in that function
* @param string $type Post type. (max. 20 characters, can not contain capital letters or spaces)
* @param array $args An array of arguments.
* @return bool Success or failure
*/
function wc_register_order_type( $type, $args = array() ) {
if ( post_type_exists( $type ) ) {
return false;
}
global $wc_order_types;
if ( ! is_array( $wc_order_types ) ) {
$wc_order_types = array();
}
// Register as a post type
if ( is_wp_error( register_post_type( $type, $args ) ) ) {
return false;
}
// Register for WC usage
$order_type_args = array(
'exclude_from_orders_screen' => false,
'add_order_meta_boxes' => true,
'exclude_from_order_count' => false,
'exclude_from_order_views' => false,
'exclude_from_order_reports' => false,
'class_name' => 'WC_Order'
);
$args = array_intersect_key( $args, $order_type_args );
$args = wp_parse_args( $args, $order_type_args );
$wc_order_types[ $type ] = $args;
return true;
}
/**
* Grant downloadable product access to the file identified by $download_id
*
@ -316,7 +442,7 @@ function wc_cancel_unpaid_orders() {
$unpaid_orders = $wpdb->get_col( $wpdb->prepare( "
SELECT posts.ID
FROM {$wpdb->posts} AS posts
WHERE posts.post_type = 'shop_order'
WHERE posts.post_type IN ('" . implode( ',', wc_get_order_types() ) . "')
AND posts.post_status = 'wc-pending'
AND posts.post_modified < %s
", $date ) );
@ -343,8 +469,14 @@ add_action( 'woocommerce_cancel_unpaid_orders', 'wc_cancel_unpaid_orders' );
* @return int
*/
function wc_processing_order_count() {
$count = wp_count_posts( 'shop_order', 'readable' );
return isset( $count->processing ) ? $count->processing : 0;
$count = 0;
foreach ( wc_get_order_types( 'order-count' ) as $type ) {
$this_count = wp_count_posts( $type, 'readable' );
$count += isset( $count->processing ) ? $count->processing : 0;
}
return $count;
}
/**
@ -383,102 +515,6 @@ function wc_ship_to_billing_address_only() {
return 'billing_only' === get_option( 'woocommerce_ship_to_destination' );
}
/**
* Get all registered order types
*
* $for optionally define what you are getting order types for so only relevent types are returned.
*
* e.g. for 'default-order-meta-boxes', 'orders-screen', 'order-count'
*
* @since 2.2
* @param string $for
* @return array
*/
function wc_get_order_types( $for = '' ) {
global $wc_order_types;
if ( ! is_array( $wc_order_types ) ) {
$wc_order_types = array();
}
switch ( $for ) {
case 'orders-screen' :
foreach ( $wc_order_types as $type => $args ) {
if ( ! $args['exclude_from_orders_screen'] ) {
$order_types[] = $type;
}
}
break;
case 'order-count' :
foreach ( $wc_order_types as $type => $args ) {
if ( ! $args['exclude_from_order_count'] ) {
$order_types[] = $type;
}
}
break;
case 'default-order-meta-boxes' :
foreach ( $wc_order_types as $type => $args ) {
if ( $args['add_order_meta_boxes'] ) {
$order_types[] = $type;
}
}
break;
default :
$order_types = array_keys( $wc_order_types );
break;
}
return apply_filters( 'wc_order_types', $order_types, $for );
}
/**
* Register order type
*
* Wrapper for register post type, as well as a method of telling WC which
* post types are types of orders, and having them treated as such.
*
* $args are passed to register_post_type, but there are a few specific to this function:
* - exclude_from_orders_screen (bool) Whether or not this order type also get shown in the main
* orders screen.
* - add_order_meta_boxes (bool) Whether or not the order type gets shop_order meta boxes.
* - exclude_from_order_count (bool) Whether or not this order type is excluded from counts.
*
* @since 2.2
* @see register_post_type for $args used in that function
* @param string $type Post type. (max. 20 characters, can not contain capital letters or spaces)
* @param array $args An array of arguments.
* @return bool Success or failure
*/
function wc_register_order_type( $type, $args ) {
if ( post_type_exists( $type ) ) {
return false;
}
global $wc_order_types;
if ( ! is_array( $wc_order_types ) ) {
$wc_order_types = array();
}
// Register as a post type
if ( is_wp_error( register_post_type( $type, $args ) ) ) {
return false;
}
// Register for WC usage
$order_type_args = array(
'exclude_from_orders_screen' => false,
'add_order_meta_boxes' => true,
'exclude_from_order_count' => false
);
$args = array_intersect( $args, $order_type_args );
$args = wp_parse_args( $args, $order_type_args );
$wc_order_types[ $type ] = $args;
return true;
}
/**
* Create a new order refund programmatically
*
@ -504,7 +540,7 @@ function wc_create_refund( $args = array() ) {
$refund_data['ID'] = $args['refund_id'];
} else {
$updating = false;
$refund_data['post_type'] = 'shop_order';
$refund_data['post_type'] = 'shop_order_refund';
$refund_data['post_status'] = 'publish';
$refund_data['ping_status'] = 'closed';
$refund_data['post_author'] = 1;

View File

@ -143,7 +143,7 @@ function wc_update_new_customer_past_orders( $customer_id ) {
$customer_orders = get_posts( array(
'numberposts' => -1,
'post_type' => 'shop_order',
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_order_statuses() ),
'fields' => 'ids',
'meta_query' => array(

View File

@ -17,7 +17,7 @@ $customer_orders = get_posts( apply_filters( 'woocommerce_my_account_my_orders_q
'numberposts' => $order_count,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => 'shop_order',
'post_type' => wc_get_order_types( 'view-orders' ),
'post_status' => array_keys( wc_get_order_statuses() )
) ) );

View File

@ -48,7 +48,7 @@ $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'woocommerce_%';
if ( ! empty( $status_options['uninstall_data'] ) ) {
// Delete posts + data
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'product', 'product_variation', 'shop_coupon', 'shop_order' );" );
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'product', 'product_variation', 'shop_coupon', 'shop_order', 'shop_order_refund' );" );
$wpdb->query( "DELETE FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE wp.ID IS NULL;" );
$wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . "woocommerce_order_items" );
$wpdb->query( "DROP TABLE IF EXISTS " . $wpdb->prefix . "woocommerce_order_itemmeta" );