Skip to content

Commit 85e3cee

Browse files
committed
Use prop getters/setters instead
1 parent ff9316b commit 85e3cee

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

includes/abstracts/abstract-wc-order.php

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -741,38 +741,22 @@ public function get_shipping_methods() {
741741
/**
742742
* Sets shipping method title.
743743
*
744-
* @param string|array $shipping_methods
744+
* @param array $shipping_method
745745
*/
746-
public function set_shipping_method( $shipping_methods ) {
747-
/*
748-
$valid_shipping_methods = array();
749-
750-
if ( ! is_array( $shipping_methods ) ) {
751-
$shipping_methods = array( $shipping_methods );
752-
}
753-
754-
foreach ( $this->get_shipping_methods() as $shipping_method ) {
755-
if ( in_array( $shipping_method->get_name(), $shipping_methods ) ) {
756-
$valid_shipping_methods[] = $shipping_method->get_method_id();
757-
}
758-
}
759-
760-
$this->set_prop( 'shipping_method', $valid_shipping_methods );
761-
*/
762-
763-
// For the time being, we cannot use `set_prop` since it would call `get_shipping_method`
764-
// to get the changes, but `get_shipping_method` will return a formatted method title instead
765-
// of the method id, which is the format stored in the DB. In order to not break BC, use this hack.
766-
// TODO: Rely only on props instead of updating post meta.
767-
update_post_meta( $this->get_id(), '_shipping_method', $valid_shipping_methods );
746+
public function set_shipping_method( $shipping_method ) {
747+
$this->set_prop( 'shipping_method', $shipping_method );
768748
}
769749

770750
/**
771751
* Gets formatted shipping method title.
772752
*
773753
* @return string
774754
*/
775-
public function get_shipping_method() {
755+
public function get_shipping_method( $context = 'view' ) {
756+
if ( 'edit' === $context ) {
757+
return $this->get_prop( 'shipping_method' );
758+
}
759+
776760
$names = array();
777761
foreach ( $this->get_shipping_methods() as $shipping_method ) {
778762
$names[] = $shipping_method->get_name();

includes/class-wc-order.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class WC_Order extends WC_Abstract_Order {
3939
'date_modified' => null,
4040
'discount_total' => 0,
4141
'discount_tax' => 0,
42+
'shipping_method' => '',
4243
'shipping_total' => 0,
4344
'shipping_tax' => 0,
4445
'cart_tax' => 0,

includes/data-stores/class-wc-order-data-store-cpt.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ protected function update_post_meta( &$order ) {
173173
'_date_completed' => 'date_completed',
174174
'_date_paid' => 'date_paid',
175175
'_cart_hash' => 'cart_hash',
176+
'_shipping_method' => 'shipping_method',
176177
);
177178

178179
$props_to_update = $this->get_props_to_update( $order, $meta_key_to_props );

0 commit comments

Comments
 (0)