From ae17d6f3bdbe4f55b5d9f569dc9624bcca588618 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 13 Feb 2019 17:52:28 +0000 Subject: [PATCH] Avoid handling wc-auto-draft WC was erroneously adding wc- prefix to the core WP auto-draft status. #22380 registered it formally but we don't need it. I've reverted #22380 and handled the prefix correctly. --- includes/class-wc-post-types.php | 8 -------- .../abstract-wc-order-data-store-cpt.php | 14 ++++++++++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/includes/class-wc-post-types.php b/includes/class-wc-post-types.php index 213cfc4992c..616b3292bb3 100644 --- a/includes/class-wc-post-types.php +++ b/includes/class-wc-post-types.php @@ -484,14 +484,6 @@ class WC_Post_Types { $order_statuses = apply_filters( 'woocommerce_register_shop_order_post_statuses', array( - 'wc-auto-draft' => array( - 'public' => false, - 'exclude_from_search' => false, - 'show_in_admin_all_list' => true, - 'show_in_admin_status_list' => true, - /* translators: %s: number of orders */ - 'label_count' => _n_noop( 'Draft (%s)', 'Draft (%s)', 'woocommerce' ), - ), 'wc-pending' => array( 'label' => _x( 'Pending payment', 'Order status', 'woocommerce' ), 'public' => false, diff --git a/includes/data-stores/abstract-wc-order-data-store-cpt.php b/includes/data-stores/abstract-wc-order-data-store-cpt.php index adcb7406d9c..d28a23b6d06 100644 --- a/includes/data-stores/abstract-wc-order-data-store-cpt.php +++ b/includes/data-stores/abstract-wc-order-data-store-cpt.php @@ -58,6 +58,9 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme $order->set_date_created( current_time( 'timestamp', true ) ); $order->set_currency( $order->get_currency() ? $order->get_currency() : get_woocommerce_currency() ); + $raw_status = $order->get_status( 'edit' ) ? $order->get_status( 'edit' ) : apply_filters( 'woocommerce_default_order_status', 'pending' ); + $status = wc_is_order_status( 'wc-' . $raw_status ) ? 'wc-' . $raw_status : $raw_status; + $id = wp_insert_post( apply_filters( 'woocommerce_new_order_data', @@ -65,7 +68,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme 'post_date' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getOffsetTimestamp() ), 'post_date_gmt' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getTimestamp() ), 'post_type' => $order->get_type( 'edit' ), - 'post_status' => 'wc-' . ( $order->get_status( 'edit' ) ? $order->get_status( 'edit' ) : apply_filters( 'woocommerce_default_order_status', 'pending' ) ), + 'post_status' => $status, 'ping_status' => 'closed', 'post_author' => 1, 'post_title' => $this->get_post_title(), @@ -73,7 +76,8 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme 'post_parent' => $order->get_parent_id( 'edit' ), 'post_excerpt' => $this->get_post_excerpt( $order ), ) - ), true + ), + true ); if ( $id && ! is_wp_error( $id ) ) { @@ -119,7 +123,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme * stored. @todo When meta is flattened, handle this during migration. */ if ( version_compare( $order->get_version( 'edit' ), '2.3.7', '<' ) && $order->get_prices_include_tax( 'edit' ) ) { - $order->set_discount_total( (double) get_post_meta( $order->get_id(), '_cart_discount', true ) - (double) get_post_meta( $order->get_id(), '_cart_discount_tax', true ) ); + $order->set_discount_total( (float) get_post_meta( $order->get_id(), '_cart_discount', true ) - (float) get_post_meta( $order->get_id(), '_cart_discount_tax', true ) ); } } @@ -140,10 +144,12 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme // Only update the post when the post data changes. if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt' ), array_keys( $changes ) ) ) { + $raw_status = $order->get_status( 'edit' ) ? $order->get_status( 'edit' ) : apply_filters( 'woocommerce_default_order_status', 'pending' ); + $status = wc_is_order_status( 'wc-' . $raw_status ) ? 'wc-' . $raw_status : $raw_status; $post_data = array( 'post_date' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getOffsetTimestamp() ), 'post_date_gmt' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getTimestamp() ), - 'post_status' => 'wc-' . ( $order->get_status( 'edit' ) ? $order->get_status( 'edit' ) : apply_filters( 'woocommerce_default_order_status', 'pending' ) ), + 'post_status' => $status, 'post_parent' => $order->get_parent_id(), 'post_excerpt' => $this->get_post_excerpt( $order ), 'post_modified' => isset( $changes['date_modified'] ) ? gmdate( 'Y-m-d H:i:s', $order->get_date_modified( 'edit' )->getOffsetTimestamp() ) : current_time( 'mysql' ),