diff --git a/includes/abstracts/abstract-wc-order.php b/includes/abstracts/abstract-wc-order.php index 44dd33bc9e6..0f6241a5f9b 100644 --- a/includes/abstracts/abstract-wc-order.php +++ b/includes/abstracts/abstract-wc-order.php @@ -741,30 +741,10 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { /** * Sets shipping method title. * - * @param string|array $shipping_methods + * @param array $shipping_method */ - public function set_shipping_method( $shipping_methods ) { - /* - $valid_shipping_methods = array(); - - if ( ! is_array( $shipping_methods ) ) { - $shipping_methods = array( $shipping_methods ); - } - - foreach ( $this->get_shipping_methods() as $shipping_method ) { - if ( in_array( $shipping_method->get_name(), $shipping_methods ) ) { - $valid_shipping_methods[] = $shipping_method->get_method_id(); - } - } - - $this->set_prop( 'shipping_method', $valid_shipping_methods ); - */ - - // For the time being, we cannot use `set_prop` since it would call `get_shipping_method` - // to get the changes, but `get_shipping_method` will return a formatted method title instead - // of the method id, which is the format stored in the DB. In order to not break BC, use this hack. - // TODO: Rely only on props instead of updating post meta. - update_post_meta( $this->get_id(), '_shipping_method', $valid_shipping_methods ); + public function set_shipping_method( $shipping_method ) { + $this->set_prop( 'shipping_method', $shipping_method ); } /** @@ -772,7 +752,11 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { * * @return string */ - public function get_shipping_method() { + public function get_shipping_method( $context = 'view' ) { + if ( 'edit' === $context ) { + return $this->get_prop( 'shipping_method' ); + } + $names = array(); foreach ( $this->get_shipping_methods() as $shipping_method ) { $names[] = $shipping_method->get_name(); diff --git a/includes/class-wc-order.php b/includes/class-wc-order.php index 0d665a6517e..a950917dad6 100644 --- a/includes/class-wc-order.php +++ b/includes/class-wc-order.php @@ -39,6 +39,7 @@ class WC_Order extends WC_Abstract_Order { 'date_modified' => null, 'discount_total' => 0, 'discount_tax' => 0, + 'shipping_method' => '', 'shipping_total' => 0, 'shipping_tax' => 0, 'cart_tax' => 0, diff --git a/includes/data-stores/class-wc-order-data-store-cpt.php b/includes/data-stores/class-wc-order-data-store-cpt.php index 150dfeeaa46..648ca27a02a 100644 --- a/includes/data-stores/class-wc-order-data-store-cpt.php +++ b/includes/data-stores/class-wc-order-data-store-cpt.php @@ -173,6 +173,7 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement '_date_completed' => 'date_completed', '_date_paid' => 'date_paid', '_cart_hash' => 'cart_hash', + '_shipping_method' => 'shipping_method', ); $props_to_update = $this->get_props_to_update( $order, $meta_key_to_props );