@@ -51,7 +51,7 @@ public static function resolve_customer( $id, AppContext $context ) {
5151 }
5252 $ customer_id = absint ( $ id );
5353 $ loader = $ context ->getLoader ( 'wc_customer ' );
54- $ loader ->buffer ( [ $ customer_id ] );
54+ $ loader ->buffer ( array ( $ customer_id ) );
5555 return new Deferred (
5656 function () use ( $ loader , $ customer_id ) {
5757 return $ loader ->load ( $ customer_id );
@@ -74,7 +74,7 @@ public static function resolve_crud_object( $id, AppContext $context ) {
7474 }
7575 $ object_id = absint ( $ id );
7676 $ loader = $ context ->getLoader ( 'wc_post_crud ' );
77- $ loader ->buffer ( [ $ object_id ] );
77+ $ loader ->buffer ( array ( $ object_id ) );
7878 return new Deferred (
7979 function () use ( $ loader , $ object_id ) {
8080 return $ loader ->load ( $ object_id );
@@ -166,6 +166,21 @@ public static function resolve_shipping_method( $id ) {
166166 return new Shipping_Method ( $ method );
167167 }
168168
169+ /**
170+ * Resolves woocommerce cart.
171+ *
172+ * @return \WC_Cart
173+ */
174+ public static function resolve_cart () {
175+ do_action ( 'woocommerce_before_calculate_totals ' , \WC ()->cart );
176+
177+ new \WC_Cart_Totals ( \WC ()->cart );
178+
179+ do_action ( 'woocommerce_after_calculate_totals ' , \WC ()->cart );
180+
181+ return \WC ()->cart ;
182+ }
183+
169184 /**
170185 * Resolves a cart item by key.
171186 *
@@ -174,9 +189,7 @@ public static function resolve_shipping_method( $id ) {
174189 * @return object
175190 */
176191 public static function resolve_cart_item ( $ id ) {
177- $ item = WC ()->cart ->get_cart_item ( $ id );
178-
179- return $ item ;
192+ return self ::resolve_cart ()->get_cart_item ( $ id );
180193 }
181194
182195 /**
@@ -187,10 +200,8 @@ public static function resolve_cart_item( $id ) {
187200 * @return object
188201 */
189202 public static function resolve_cart_fee ( $ id ) {
190- $ fees = WC ()->cart ->get_fees ();
191-
192- if ( ! empty ( $ fees [ $ id ] ) ) {
193- return $ fees [ $ id ];
203+ if ( ! empty ( self ::resolve_cart ()->get_fees ()[ $ id ] ) ) {
204+ return self ::resolve_cart ()->get_fees ()[ $ id ];
194205 }
195206
196207 return null ;
0 commit comments