'', 'countries' => jsonpage_supported_countries(), 'invalid_vat' => 'warn', // block, warn or charge_vat. 'closed' => 'warn', // block, warn or allow. 'auto_exempt' => 'yes', 'require_vat' => 'no', 'forms_enabled' => 'yes', ); } /** * Settings merged with the defaults. * * @return array */ function jsonpage_settings() { $saved = get_option( 'jsonpage_settings', array() ); if ( ! is_array( $saved ) ) { $saved = array(); } $settings = array_merge( jsonpage_default_settings(), $saved ); if ( ! is_array( $settings['countries'] ) || empty( $settings['countries'] ) ) { $settings['countries'] = jsonpage_supported_countries(); } return $settings; } /** * One setting. * * @param string $key Setting name. * @return mixed */ function jsonpage_setting( $key ) { $settings = jsonpage_settings(); return isset( $settings[ $key ] ) ? $settings[ $key ] : null; } /** * Countries the shop accepts, limited to the countries served. * * @return string[] */ function jsonpage_allowed_countries() { $allowed = array_intersect( jsonpage_supported_countries(), (array) jsonpage_setting( 'countries' ) ); return array_values( $allowed ); } /** * Sign-up page of Jsonpage, with the origin of the sign-up. * * @return string */ function jsonpage_signup_url() { return 'https://jsonpage.com/account?source=woocommerce'; } /** * Removes spaces, dots and hyphens and upper-cases a VAT number. * * @param string $raw Value typed by the customer. * @return string */ function jsonpage_normalize_vat( $raw ) { $raw = is_string( $raw ) ? $raw : ''; return strtoupper( preg_replace( '/[\s.\-]+/', '', $raw ) ); } /** * Countries whose VAT numbers can be verified. The United Kingdom has autocomplete and company * records, but its VAT numbers are not checked. * * @return string[] */ function jsonpage_vat_countries() { return array( 'FR', 'BE', 'CH', 'NO', 'FI', 'LV' ); } /** * Country of a VAT number, from its prefix. Empty when its country cannot be verified. * * @param string $vat Normalised VAT number. * @return string */ function jsonpage_vat_country( $vat ) { $vat = jsonpage_normalize_vat( $vat ); if ( 0 === strpos( $vat, 'CHE' ) ) { return 'CH'; } $prefix = substr( $vat, 0, 2 ); return in_array( $prefix, jsonpage_vat_countries(), true ) ? $prefix : ''; } /** * Readable name of a verification status. * * @param string $status Status stored on the order or the customer. * @return string */ function jsonpage_status_label( $status ) { switch ( $status ) { case 'valid': return __( 'Verified', 'jsonpage' ); case 'invalid': return __( 'Invalid', 'jsonpage' ); case 'pending': return __( 'Check pending', 'jsonpage' ); case 'unverified': return __( 'Not verified', 'jsonpage' ); case 'unchecked': return __( 'To be checked again', 'jsonpage' ); default: return __( 'Not checked', 'jsonpage' ); } } /** * Suggested text for the privacy policy page (Settings > Privacy). */ function jsonpage_privacy_policy_content() { if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) { return; } $text = '
' . esc_html__( 'When a visitor types in a company field (checkout, account creation or a contact form), the text typed, or the VAT number entered, is sent from this site to the Jsonpage service (api.jsonpage.com) to suggest companies and to verify the VAT number. The visitor browser never contacts the service directly and the visitor IP address is not sent.', 'jsonpage' ) . '
'; $text .= '' . esc_html__( 'On orders and customer accounts this site stores the VAT number, the verification status and the verification date.', 'jsonpage' ) . '
'; wp_add_privacy_policy_content( 'Jsonpage', wp_kses_post( wpautop( $text, false ) ) ); } add_action( 'admin_init', 'jsonpage_privacy_policy_content' );