countries ? (array) WC()->countries->get_european_union_countries() : array(); return array_values( array_unique( array_merge( array_map( 'strval', $eu ), self::EEA_EXTRA ) ) ); } /** * True when WooCommerce's selling locations take in a country of the EU or the EEA. * * @return bool */ public static function sells_to_eea() { if ( ! function_exists( 'WC' ) || ! WC()->countries ) { return false; } return array() !== array_intersect( array_keys( (array) WC()->countries->get_allowed_countries() ), self::eea_countries() ); } /** * WooCommerce's selling locations in a few words: all countries, all but * some, or specific countries. * * @return string */ public static function selling_label() { $allowed = (string) get_option( 'woocommerce_allowed_countries', 'all' ); if ( 'specific' === $allowed ) { return __( 'specific countries', 'careback' ); } if ( 'all_except' === $allowed ) { return __( 'all countries, except some', 'careback' ); } return __( 'all countries', 'careback' ); } /** * Withdrawals still being worked on: the open statuses, the withdrawal type. * * @param Requests_Repository $requests The requests table. * @return int */ public static function open_withdrawals( Requests_Repository $requests ) { return (int) $requests->count( Statuses::open(), '', array( 'withdrawal' ) ); } /** * The request list narrowed to the open withdrawals. * * @return string */ public static function open_withdrawals_url() { $query = 'admin.php?page=careback&type[]=withdrawal'; foreach ( Statuses::open() as $status ) { $query .= '&status[]=' . rawurlencode( (string) $status ); } return admin_url( $query ); } /** * The day it was switched off, in the site's date format, or ''. * * @param Settings $settings Plugin settings. * @return string */ public static function off_since( Settings $settings ) { $at = (int) $settings->get( 'withdrawal_off_at', 0 ); return $at > 0 ? (string) wp_date( (string) get_option( 'date_format' ), $at ) : ''; } /** * What the settings form asks of the switch: the values to store and the * result the redirect carries ('' when nothing changed). Off is stored only * with the confirmation; On always. A form that sends no switch changes * nothing. The caller checked the nonce and the capability. * * @param Settings $settings Settings as stored. * @param array $posted The posted form (Admin::save()). * @return array{0:array,1:string} */ public static function from_post( Settings $settings, array $posted ) { if ( ! isset( $posted['withdrawal_enabled'] ) || ! is_scalar( $posted['withdrawal_enabled'] ) ) { return array( array(), '' ); } $want_on = '0' !== sanitize_key( $posted['withdrawal_enabled'] ); $confirm = ! empty( $posted['withdrawal_off_confirm'] ); $is_on = Routes::withdrawal_offered( $settings ); if ( $want_on ) { return $is_on ? array( array(), '' ) : array( array( 'withdrawal_enabled' => 1, 'withdrawal_off_at' => 0, 'withdrawal_off_by' => 0, ), 'on', ); } if ( ! $is_on ) { return array( array(), '' ); } if ( ! $confirm ) { return array( array(), 'unconfirmed' ); } return array( array( 'withdrawal_enabled' => 0, 'withdrawal_off_at' => time(), 'withdrawal_off_by' => get_current_user_id(), ), 'off', ); } /** * The notice at the top of Settings after a save: the switch's result, or * "Settings saved." alone. * * @return void */ public static function saved_notice() { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- a notice after the redirect; nothing is changed. if ( ! isset( $_GET['updated'] ) ) { return; } $result = isset( $_GET[ self::RESULT_ARG ] ) ? sanitize_key( wp_unslash( $_GET[ self::RESULT_ARG ] ) ) : ''; // phpcs:enable WordPress.Security.NonceVerification.Recommended if ( 'unconfirmed' === $result ) { printf( '

%1$s %2$s %3$s %5$s

', esc_html__( 'Settings saved, except one:', 'careback' ), esc_html__( 'statutory withdrawal is still on.', 'careback' ), esc_html__( 'To switch it off, tick the confirmation below and save again.', 'careback' ), esc_attr( self::ANCHOR ), esc_html__( 'Go to the setting', 'careback' ) ); return; } if ( 'off' === $result ) { $text = __( 'Settings saved. Statutory withdrawal is off: the form offers only your voluntary return.', 'careback' ); } elseif ( 'on' === $result ) { $text = __( 'Settings saved. Statutory withdrawal is on: the form offers it again from now on.', 'careback' ); } else { $text = __( 'Settings saved.', 'careback' ); } printf( '

%s

', esc_html( $text ) ); } /** * The row of the switch on Settings: the two radio buttons in a fieldset; * while it is on, the confirmation under them — printed for a browser * without JavaScript too, read only when Off is sent; while it is off, since * when and by whom, and the withdrawals filed before that are still open. * * @param Settings $settings Settings the screen prints. * @param Requests_Repository $requests The requests table. * @return void */ public static function render_row( Settings $settings, Requests_Repository $requests ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- the result of the redirect; nothing is changed. $unconfirmed = isset( $_GET[ self::RESULT_ARG ] ) && 'unconfirmed' === sanitize_key( wp_unslash( $_GET[ self::RESULT_ARG ] ) ); $on = Routes::withdrawal_offered( $settings ); $days = (int) $settings->get( 'return_window_days', 30 ); ?>

0 ) : ?>

get( 'withdrawal_off_by', 0 ) ); if ( '' !== $since && $user ) { // One sentence of its own after the "Off" badge, so no language has to continue the badge. /* translators: 1: date it was switched off, 2: name of the user who switched it off. */ return sprintf( __( 'Switched off on %1$s by %2$s. Customers see only your voluntary return.', 'careback' ), $since, $user->display_name ); } if ( '' !== $since ) { /* translators: %s: date it was switched off. */ return sprintf( __( 'Switched off on %s. Customers see only your voluntary return.', 'careback' ), $since ); } return __( 'Customers see only your voluntary return.', 'careback' ); } }