'; echo esc_html__( '1account Age Verification requires WooCommerce. Install and activate WooCommerce, then try again.', '1account-age-verification' ); echo '
'; } add_action( 'plugins_loaded', 'oneacc_boot' ); function oneacc_push_api_script_url() { $host = oneacc_api_host(); // Production is served at www.1account.net. The QA certificate is only // for 1accountqa.net, so www.1accountqa.net fails the TLS handshake. $web_host = ( '1accountqa.net' === $host ) ? $host : 'www.' . $host; return 'https://' . $web_host . '/pushApi/index.js'; } /** * Order-status rows used when a merchant has not saved their own mapping. * Left value is the WooCommerce status name. Right value is the age-check result. */ function oneacc_default_order_status_settings() { return \Oneacc\AgeCheck::default_status_settings(); } function oneacc_get_order_status_settings() { return \Oneacc\AgeCheck::status_settings( get_option( 'wc_oneacc_order_status_settings' ) ); } function oneacc_order_is_completed( $order ) { return is_object( $order ) && is_callable( array( $order, 'get_status' ) ) && \Oneacc\AgeCheck::is_completed_status( $order->get_status() ); } /** * Store URL sent on a new incomplete age-check record. No trailing slash and no /shop/ suffix. */ function oneacc_av_store_url() { return untrailingslashit( site_url() ); } /** * Store URL for an update. Uses the value saved at create time when the order has one. * * @param WC_Order|object|null $order Order the incomplete record belongs to. */ function oneacc_av_store_url_for_order( $order ) { $saved = ''; if ( is_object( $order ) && is_callable( array( $order, 'get_meta' ) ) ) { $saved = $order->get_meta( '_oneaccount_av_store_url' ); } if ( is_string( $saved ) && '' !== $saved ) { return $saved; } return oneacc_av_store_url(); } /** * POST or PUT JSON through the WordPress HTTP API. * * @param string $url Request URL. * @param string $method POST or PUT. * @param string $body JSON request body. * @return array{body: string, http_code: int, error: string} */ function oneacc_remote_json( $url, $method, $body ) { $response = wp_remote_request( $url, array( 'method' => $method, 'timeout' => oneacc_incomplete_av_timeout(), 'redirection' => 10, 'httpversion' => '1.1', 'headers' => array( 'Content-Type' => 'application/json', ), 'body' => $body, ) ); if ( is_wp_error( $response ) ) { return array( 'body' => '', 'http_code' => 0, 'error' => $response->get_error_message(), ); } return array( 'body' => (string) wp_remote_retrieve_body( $response ), 'http_code' => (int) wp_remote_retrieve_response_code( $response ), 'error' => '', ); } function oneacc_render_order_av_status($order) { $value = strtoupper( str_replace( ' ', '_', (string) $order->get_meta( 'av_order_tag_key' ) ) ); $legacy = array( 'AV_PASS' => 'AV_SUCCESS', 'AV_FAIL' => 'AV_FAILED', 'AV_SUCCESS' => 'AV_SUCCESS', 'AV_FAILED' => 'AV_FAILED', 'NO_UK_USER' => 'NON_UK_USER', ); if ( isset( $legacy[ $value ] ) ) { $value = $legacy[ $value ]; } // Shown only. The 1account backend writes av_order_tag_key; the order screen must not. echo 'Order AV status:
';
echo esc_html( $value !== '' ? $value : '—' );
echo '