$settings Setup settings. * @param array $facts Runtime facts. */ public function create( array $settings, array $facts ): CommerceContext { $timezone = function_exists( 'wp_timezone_string' ) ? (string) wp_timezone_string() : 'UTC'; $timezone = '' !== $timezone ? $timezone : 'UTC'; try { $occurred_at = new \DateTimeImmutable( 'now', new \DateTimeZone( $timezone ) ); } catch ( \Throwable $exception ) { unset( $exception ); $timezone = 'UTC'; $occurred_at = new \DateTimeImmutable( 'now', new \DateTimeZone( 'UTC' ) ); } $merchant = (array) ( $settings['merchant'] ?? array() ); $sales = (array) ( $settings['sales'] ?? array() ); $languages = (array) ( $settings['languages'] ?? array() ); $terms = (array) ( $settings['terms'] ?? array() ); $delivery = (array) ( $settings['delivery'] ?? array() ); $documents = (array) ( $settings['documents'] ?? array() ); return new CommerceContext( new MerchantContext( array( 'profile' => $merchant, 'languages' => $languages, 'sales' => $sales, 'establishment' => (string) ( $merchant['establishment'] ?? '' ), 'country' => (string) ( $merchant['country'] ?? 'BA' ), ) ), new ConsumerContext( array( 'country' => 'BA', 'jurisdiction' => ! empty( $sales['sells_across_bih'] ) ? 'BA_ALL' : (string) ( $merchant['establishment'] ?? '' ), ) ), new TransactionContext( array( 'business_model' => 'B2C', 'transaction_type' => 'PHYSICAL_GOODS', 'sales_channel' => 'WOOCOMMERCE_DISTANCE', 'cross_entity_mode' => (string) ( $sales['cross_entity_mode'] ?? 'PRECAUTIONARY_UNION' ), 'sells_across_bih' => ! empty( $sales['sells_across_bih'] ), ) ), new CheckoutContext( array( 'channel' => (string) ( $facts['checkout_mode'] ?? 'unknown' ), 'terms' => $terms, 'delivery' => $delivery, 'documents' => $documents, ) ), new TemporalContext( $occurred_at, $timezone ), new EntitlementContext( EntitlementContext::FREE ) ); } }