File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -738,6 +738,35 @@ public function get_shipping_methods() {
738738 return $ this ->get_items ( 'shipping ' );
739739 }
740740
741+ /**
742+ * Sets shipping method title.
743+ *
744+ * @param string|array $shipping_methods
745+ */
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 );
768+ }
769+
741770 /**
742771 * Gets formatted shipping method title.
743772 *
You can’t perform that action at this time.
0 commit comments