session instanceof \WC_Session ? $wc->session : null; $customer = $wc && $wc->customer instanceof \WC_Customer ? $wc->customer : null; $shipping = $session ? $session->get( 'chosen_shipping_methods', array() ) : array(); $shipping = is_array( $shipping ) ? array_values( array_filter( array_map( 'strval', $shipping ) ) ) : array(); $payment = $session ? $session->get( 'chosen_payment_method', '' ) : ''; return new Context( $cart, $customer, $location, $shipping, is_string( $payment ) ? $payment : '', function_exists( 'get_woocommerce_currency' ) ? (string) get_woocommerce_currency() : '', null !== $cart && isset( $cart->recurring_cart_key ) ); } /** * Context for the current cart. * * @param string $location Location. */ public function current( string $location ): Context { $cart = function_exists( 'WC' ) && WC()->cart instanceof \WC_Cart ? WC()->cart : null; return $this->from_cart( $cart, $location ); } }