CartExtension::STORE_NAMESPACE, 'callback' => array( $this, 'handle' ), ) ); } /** * Handles the update. * * @param mixed $data Request `data`. * @throws \Automattic\WooCommerce\StoreApi\Exceptions\RouteException On an invalid action. */ public function handle( mixed $data ): void { $data = is_array( $data ) ? $data : array(); $action = sanitize_key( is_string( $data['action'] ?? null ) ? $data['action'] : 'set' ); $context = $this->contexts->current( 'checkout_block' ); if ( 'clear' === $action ) { $this->service->clear_selections( $context, 'store_api' ); return; } // `resync`: nothing to store; the Store API recalculates and returns the cart afterwards. if ( 'resync' === $action ) { return; } if ( 'set' !== $action ) { if ( class_exists( \Automattic\WooCommerce\StoreApi\Exceptions\RouteException::class ) ) { throw new \Automattic\WooCommerce\StoreApi\Exceptions\RouteException( 'extrova_invalid_action', esc_html__( 'Invalid checkout extras action.', 'extrova' ), 400 ); } return; } $raw = is_array( $data['selections'] ?? null ) ? $data['selections'] : array(); $this->service->set_selections( $raw, $context, 'store_api' ); } }