@@ -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 ();
0 commit comments