is_default_theme(); return ( current_user_can( 'install_themes' ) && current_user_can( 'switch_themes' ) && ! is_multisite() && ! $support_woocommerce ); } /** * Is the user using a default WP theme? * * @return boolean */ protected function is_default_theme() { return wc_is_active_theme( array( 'twentyseventeen', 'twentysixteen', 'twentyfifteen', 'twentyfourteen', 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten', ) ); } /** * The "automated tax" extra should only be shown if the current user can * install plugins and the store is in a supported country. */ protected function should_show_automated_tax_extra() { if ( ! current_user_can( 'install_plugins' ) ) { return false; } $country_code = WC()->countries->get_base_country(); // https://developers.taxjar.com/api/reference/#countries . $tax_supported_countries = array_merge( array( 'US', 'CA', 'AU' ), WC()->countries->get_european_union_countries() ); return in_array( $country_code, $tax_supported_countries, true ); } /** * Show the setup wizard. */ public function setup_wizard() { if ( empty( $_GET['page'] ) || 'wc-setup' !== $_GET['page'] ) { // WPCS: CSRF ok, input var ok. return; } $default_steps = array( 'store_setup' => array( 'name' => __( 'Store setup', 'woocommerce' ), 'view' => array( $this, 'wc_setup_store_setup' ), 'handler' => array( $this, 'wc_setup_store_setup_save' ), ), 'payment' => array( 'name' => __( 'Payment', 'woocommerce' ), 'view' => array( $this, 'wc_setup_payment' ), 'handler' => array( $this, 'wc_setup_payment_save' ), ), 'shipping' => array( 'name' => __( 'Shipping', 'woocommerce' ), 'view' => array( $this, 'wc_setup_shipping' ), 'handler' => array( $this, 'wc_setup_shipping_save' ), ), 'extras' => array( 'name' => __( 'Extras', 'woocommerce' ), 'view' => array( $this, 'wc_setup_extras' ), 'handler' => array( $this, 'wc_setup_extras_save' ), ), 'activate' => array( 'name' => __( 'Activate', 'woocommerce' ), 'view' => array( $this, 'wc_setup_activate' ), 'handler' => array( $this, 'wc_setup_activate_save' ), ), 'next_steps' => array( 'name' => __( 'Ready!', 'woocommerce' ), 'view' => array( $this, 'wc_setup_ready' ), 'handler' => '', ), ); // Hide the extras step if this store/user isn't eligible for them. if ( ! $this->should_show_theme_extra() && ! $this->should_show_automated_tax_extra() ) { unset( $default_steps['extras'] ); } // Hide shipping step if the store is selling digital products only. if ( 'virtual' === get_option( 'woocommerce_product_type' ) ) { unset( $default_steps['shipping'] ); } // Whether or not there is a pending background install of Jetpack. $pending_jetpack = ! class_exists( 'Jetpack' ) && get_option( 'woocommerce_setup_background_installing_jetpack' ); $this->steps = apply_filters( 'woocommerce_setup_wizard_steps', $default_steps ); $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) ); // WPCS: CSRF ok, input var ok. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; wp_register_script( 'jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true ); wp_register_script( 'selectWoo', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js', array( 'jquery' ), '1.0.0' ); wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), WC_VERSION ); wp_localize_script( 'wc-enhanced-select', 'wc_enhanced_select_params', array( 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ), 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ), 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ), 'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ), 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ), 'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ), 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ), 'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ), 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'woocommerce' ), 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'woocommerce' ), 'ajax_url' => admin_url( 'admin-ajax.php' ), 'search_products_nonce' => wp_create_nonce( 'search-products' ), 'search_customers_nonce' => wp_create_nonce( 'search-customers' ), ) ); wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC_VERSION ); wp_enqueue_style( 'wc-setup', WC()->plugin_url() . '/assets/css/wc-setup.css', array( 'dashicons', 'install' ), WC_VERSION ); wp_register_script( 'wc-setup', WC()->plugin_url() . '/assets/js/admin/wc-setup' . $suffix . '.js', array( 'jquery', 'wc-enhanced-select', 'jquery-blockui', 'wp-util' ), WC_VERSION ); wp_localize_script( 'wc-setup', 'wc_setup_params', array( 'pending_jetpack_install' => $pending_jetpack ? 'yes' : 'no', ) ); // @codingStandardsIgnoreStart if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) { call_user_func( $this->steps[ $this->step ]['handler'], $this ); } // @codingStandardsIgnoreEnd ob_start(); $this->setup_wizard_header(); $this->setup_wizard_steps(); $this->setup_wizard_content(); $this->setup_wizard_footer(); exit; } /** * Get the URL for the next step's screen. * * @param string $step slug (default: current step). * @return string URL for next step if a next step exists. * Admin URL if it's the last step. * Empty string on failure. * @since 3.0.0 */ public function get_next_step_link( $step = '' ) { if ( ! $step ) { $step = $this->step; } $keys = array_keys( $this->steps ); if ( end( $keys ) === $step ) { return admin_url(); } $step_index = array_search( $step, $keys, true ); if ( false === $step_index ) { return ''; } return add_query_arg( 'step', $keys[ $step_index + 1 ], remove_query_arg( 'activate_error' ) ); } /** * Setup Wizard Header. */ public function setup_wizard_header() { ?> > <?php esc_html_e( 'WooCommerce › Setup Wizard', 'woocommerce' ); ?>

WooCommerce

step ) : ?> step ) : ?> steps; $selected_features = array_filter( $this->wc_setup_activate_get_feature_list() ); // Hide the activate step if Jetpack is already active, unless WooCommerce Services // features are selected, or unless the Activate step was already taken. if ( class_exists( 'Jetpack' ) && Jetpack::is_active() && empty( $selected_features ) && 'yes' !== get_transient( 'wc_setup_activated' ) ) { unset( $output_steps['activate'] ); } ?>
    $step ) { $is_completed = array_search( $this->step, array_keys( $this->steps ), true ) > array_search( $step_key, array_keys( $this->steps ), true ); if ( $step_key === $this->step ) { ?>
'; if ( ! empty( $this->steps[ $this->step ]['view'] ) ) { call_user_func( $this->steps[ $this->step ]['view'], $this ); } echo ''; } /** * Initial "store setup" step. * Location, product type, page setup, and tracking opt-in. */ public function wc_setup_store_setup() { $address = WC()->countries->get_base_address(); $address_2 = WC()->countries->get_base_address_2(); $city = WC()->countries->get_base_city(); $state = WC()->countries->get_base_state(); $country = WC()->countries->get_base_country(); $postcode = WC()->countries->get_base_postcode(); $currency = get_option( 'woocommerce_currency', 'GBP' ); $product_type = get_option( 'woocommerce_product_type', 'both' ); $sell_in_person = get_option( 'woocommerce_sell_in_person', 'none_selected' ); if ( empty( $country ) ) { $user_location = WC_Geolocation::geolocate_ip(); $country = $user_location['country']; $state = $user_location['state']; } elseif ( empty( $state ) ) { $state = '*'; } $locale_info = include WC()->plugin_path() . '/i18n/locale-info.php'; $currency_by_country = wp_list_pluck( $locale_info, 'currency_code' ); ?>

/>

' . esc_html__( 'Read more about what we collect.', 'woocommerce' ) . ''; ?>

plugin_path() . '/i18n/locale-info.php'; $country = WC()->countries->get_base_country(); // Set currency formatting options based on chosen location and currency. if ( isset( $locale_info[ $country ] ) && $locale_info[ $country ]['currency_code'] === $currency_code ) { update_option( 'woocommerce_currency_pos', $locale_info[ $country ]['currency_pos'] ); update_option( 'woocommerce_price_decimal_sep', $locale_info[ $country ]['decimal_sep'] ); update_option( 'woocommerce_price_num_decimals', $locale_info[ $country ]['num_decimals'] ); update_option( 'woocommerce_price_thousand_sep', $locale_info[ $country ]['thousand_sep'] ); } if ( $tracking ) { update_option( 'woocommerce_allow_tracking', 'yes' ); WC_Tracker::send_tracking_data( true ); } else { update_option( 'woocommerce_allow_tracking', 'no' ); } WC_Install::create_pages(); wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) ); exit; } /** * Finishes replying to the client, but keeps the process running for further (async) code execution. * * @see https://core.trac.wordpress.org/ticket/41358 . */ protected function close_http_connection() { // Only 1 PHP process can access a session object at a time, close this so the next request isn't kept waiting. // @codingStandardsIgnoreStart if ( session_id() ) { session_write_close(); } // @codingStandardsIgnoreEnd wc_set_time_limit( 0 ); // fastcgi_finish_request is the cleanest way to send the response and keep the script running, but not every server has it. if ( is_callable( 'fastcgi_finish_request' ) ) { fastcgi_finish_request(); } else { // Fallback: send headers and flush buffers. if ( ! headers_sent() ) { header( 'Connection: close' ); } @ob_end_flush(); // @codingStandardsIgnoreLine. flush(); } } /** * Function called after the HTTP request is finished, so it's executed without the client having to wait for it. * * @see WC_Admin_Setup_Wizard::install_plugin * @see WC_Admin_Setup_Wizard::install_theme */ public function run_deferred_actions() { $this->close_http_connection(); foreach ( $this->deferred_actions as $action ) { call_user_func_array( $action['func'], $action['args'] ); // Clear the background installation flag if this is a plugin. if ( isset( $action['func'][1] ) && 'background_installer' === $action['func'][1] && isset( $action['args'][0] ) ) { delete_option( 'woocommerce_setup_background_installing_' . $action['args'][0] ); } } } /** * Helper method to queue the background install of a plugin. * * @param string $plugin_id Plugin id used for background install. * @param array $plugin_info Plugin info array containing at least main file and repo slug. */ protected function install_plugin( $plugin_id, $plugin_info ) { // Make sure we don't trigger multiple simultaneous installs. if ( get_option( 'woocommerce_setup_background_installing_' . $plugin_id ) ) { return; } if ( ! empty( $plugin_info['file'] ) && is_plugin_active( $plugin_info['file'] ) ) { return; } if ( empty( $this->deferred_actions ) ) { add_action( 'shutdown', array( $this, 'run_deferred_actions' ) ); } array_push( $this->deferred_actions, array( 'func' => array( 'WC_Install', 'background_installer' ), 'args' => array( $plugin_id, $plugin_info ), ) ); // Set the background installation flag for this plugin. update_option( 'woocommerce_setup_background_installing_' . $plugin_id, true ); } /** * Helper method to queue the background install of a theme. * * @param string $theme_id Theme id used for background install. */ protected function install_theme( $theme_id ) { if ( empty( $this->deferred_actions ) ) { add_action( 'shutdown', array( $this, 'run_deferred_actions' ) ); } array_push( $this->deferred_actions, array( 'func' => array( 'WC_Install', 'theme_background_installer' ), 'args' => array( $theme_id ), ) ); } /** * Helper method to install Jetpack. */ protected function install_jetpack() { $this->install_plugin( 'jetpack', array( 'file' => 'jetpack/jetpack.php', 'name' => __( 'Jetpack', 'woocommerce' ), 'repo-slug' => 'jetpack', ) ); } /** * Helper method to install WooCommerce Services and its Jetpack dependency. */ protected function install_woocommerce_services() { $this->install_jetpack(); $this->install_plugin( 'woocommerce-services', array( 'file' => 'woocommerce-services/woocommerce-services.php', 'name' => __( 'WooCommerce Services', 'woocommerce' ), 'repo-slug' => 'woocommerce-services', ) ); } /** * Get the WCS shipping carrier for a given country code. * * Can also be used to determine if WCS supports a given country. * * @param string $country_code Country Code. * @param string $currency_code Currecy Code. * @return bool|string Carrier name if supported, boolean False otherwise. */ protected function get_wcs_shipping_carrier( $country_code, $currency_code ) { switch ( array( $country_code, $currency_code ) ) { case array( 'US', 'USD' ): return 'USPS'; case array( 'CA', 'CAD' ): return 'Canada Post'; default: return false; } } /** * Get shipping methods based on country code. * * @param string $country_code Country code. * @param string $currency_code Currency code. * @return array */ protected function get_wizard_shipping_methods( $country_code, $currency_code ) { $shipping_methods = array( 'live_rates' => array( 'name' => __( 'Live Rates', 'woocommerce' ), 'description' => __( 'WooCommerce Services and Jetpack will be installed and activated for you.', 'woocommerce' ), ), 'flat_rate' => array( 'name' => __( 'Flat Rate', 'woocommerce' ), 'description' => __( 'Set a fixed price to cover shipping costs.', 'woocommerce' ), 'settings' => array( 'cost' => array( 'type' => 'text', 'default_value' => __( 'Cost', 'woocommerce' ), 'description' => __( 'What would you like to charge for flat rate shipping?', 'woocommerce' ), 'required' => true, ), ), ), 'free_shipping' => array( 'name' => __( 'Free Shipping', 'woocommerce' ), 'description' => __( "Don't charge for shipping.", 'woocommerce' ), ), ); $live_rate_carrier = $this->get_wcs_shipping_carrier( $country_code, $currency_code ); if ( false === $live_rate_carrier || ! current_user_can( 'install_plugins' ) ) { unset( $shipping_methods['live_rates'] ); } return $shipping_methods; } /** * Render the available shipping methods for a given country code. * * @param string $country_code Country code. * @param string $currency_code Currency code. * @param string $input_prefix Input prefix. */ protected function shipping_method_selection_form( $country_code, $currency_code, $input_prefix ) { $live_rate_carrier = $this->get_wcs_shipping_carrier( $country_code, $currency_code ); $selected = $live_rate_carrier ? 'live_rates' : 'flat_rate'; $shipping_methods = $this->get_wizard_shipping_methods( $country_code, $currency_code ); ?>
$method ) : ?>

$method ) : ?>
$setting ) : ?> />

countries->get_base_country(); $country_name = WC()->countries->countries[ $country_code ]; $prefixed_country_name = WC()->countries->estimated_for_prefix( $country_code ) . $country_name; $currency_code = get_woocommerce_currency(); $wcs_carrier = $this->get_wcs_shipping_carrier( $country_code, $currency_code ); $existing_zones = WC_Shipping_Zones::get_zones(); $dimension_unit = get_option( 'woocommerce_dimension_unit' ); $weight_unit = get_option( 'woocommerce_weight_unit' ); $locale_info = include WC()->plugin_path() . '/i18n/locale-info.php'; if ( ! $weight_unit && isset( $locale_info[ $country_code ] ) ) { $weight_unit = $locale_info[ $country_code ]['weight_unit']; } else { $weight_unit = $weight_unit ? $weight_unit : 'kg'; } if ( ! $dimension_unit && isset( $locale_info[ $country_code ] ) ) { $dimension_unit = $locale_info[ $country_code ]['dimension_unit']; } else { $dimension_unit = $dimension_unit ? $dimension_unit : 'cm'; } if ( ! empty( $existing_zones ) ) { $intro_text = __( 'How would you like units on your store displayed?', 'woocommerce' ); } elseif ( $wcs_carrier ) { $intro_text = sprintf( /* translators: %1$s: country name including the 'the' prefix, %2$s: shipping carrier name */ __( "You're all set up to ship anywhere in %1\$s, and outside of it. We recommend using live rates (which are powered by our WooCommerce Services plugin and Jetpack) to get accurate %2\$s shipping prices to cover the cost of order fulfillment.", 'woocommerce' ), $prefixed_country_name, $wcs_carrier ); } else { $intro_text = sprintf( /* translators: %s: country name including the 'the' prefix if needed */ __( "You can choose which countries you'll be shipping to and with which methods. To get started, we've set you up with shipping inside and outside of %s.", 'woocommerce' ), $prefixed_country_name ); } ?>

get_next_step_link() ) ); exit; } // Install WooCommerce Services if live rates were selected. if ( ( $setup_domestic && 'live_rates' === $domestic_method ) || ( $setup_intl && 'live_rates' === $intl_method ) ) { $this->install_woocommerce_services(); } /* * If enabled, create a shipping zone containing the country the * store is located in, with the selected method preconfigured. */ if ( $setup_domestic ) { $country = WC()->countries->get_base_country(); $zone = new WC_Shipping_Zone( null ); $zone->set_zone_order( 0 ); $zone->add_location( $country, 'country' ); if ( 'live_rates' === $domestic_method ) { // Signal WooCommerce Services to setup the domestic zone. update_option( 'woocommerce_setup_domestic_live_rates_zone', true, 'no' ); } else { $instance_id = $zone->add_shipping_method( $domestic_method ); } $zone->save(); // Save chosen shipping method settings (using REST controller for convenience). if ( isset( $instance_id ) && ! empty( $_POST['shipping_zones']['domestic'][ $domestic_method ] ) ) { // WPCS: input var ok. $method_controller = new WC_REST_Shipping_Zone_Methods_Controller(); // @codingStandardsIgnoreStart $method_controller->update_item( array( 'zone_id' => $zone->get_id(), 'instance_id' => $instance_id, 'settings' => wp_unslash( $_POST['shipping_zones']['domestic'][ $domestic_method ] ), ) ); // @codingStandardsIgnoreEnd } } // If enabled, set the selected method for the "rest of world" zone. if ( $setup_intl ) { if ( 'live_rates' === $intl_method ) { // Signal WooCommerce Services to setup the international zone. update_option( 'woocommerce_setup_intl_live_rates_zone', true, 'no' ); } else { $zone = new WC_Shipping_Zone( 0 ); $instance_id = $zone->add_shipping_method( $intl_method ); $zone->save(); } // Save chosen shipping method settings (using REST controller for convenience). if ( isset( $instance_id ) && ! empty( $_POST['shipping_zones']['intl'][ $intl_method ] ) ) { // WPCS: input var ok. $method_controller = new WC_REST_Shipping_Zone_Methods_Controller(); // @codingStandardsIgnoreStart $method_controller->update_item( array( 'zone_id' => $zone->get_id(), 'instance_id' => $instance_id, 'settings' => wp_unslash( $_POST['shipping_zones']['intl'][ $intl_method ] ), ) ); // @codingStandardsIgnoreEnd } } // Notify the user that no shipping methods are configured. if ( ! $setup_domestic && ! $setup_intl ) { WC_Admin_Notices::add_notice( 'no_shipping_methods' ); } wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) ); exit; } /** * Is Stripe country supported * https://stripe.com/global . * * @param string $country_code Country code. */ protected function is_stripe_supported_country( $country_code ) { $stripe_supported_countries = array( 'AU', 'AT', 'BE', 'CA', 'DK', 'FI', 'FR', 'DE', 'HK', 'IE', 'JP', 'LU', 'NL', 'NZ', 'NO', 'SG', 'ES', 'SE', 'CH', 'GB', 'US', ); return in_array( $country_code, $stripe_supported_countries, true ); } /** * Is Klarna Checkout country supported * * @param string $country_code Country code. */ protected function is_klarna_checkout_supported_country( $country_code ) { $supported_countries = array( 'SE', // Sweden. 'FI', // Finland. 'NO', // Norway. 'NL', // Netherlands. ); return in_array( $country_code, $supported_countries, true ); } /** * Is Klarna Payments country supported * * @param string $country_code Country code. */ protected function is_klarna_payments_supported_country( $country_code ) { $supported_countries = array( 'DK', // Denmark. 'DE', // Germany. 'AT', // Austria. ); return in_array( $country_code, $supported_countries, true ); } /** * Is Square country supported * * @param string $country_code Country code. */ protected function is_square_supported_country( $country_code ) { $square_supported_countries = array( 'US', 'CA', 'JP', 'GB', 'AU', ); return in_array( $country_code, $square_supported_countries, true ); } /** * Helper method to retrieve the current user's email address. * * @return string Email address */ protected function get_current_user_email() { $current_user = wp_get_current_user(); $user_email = $current_user->user_email; return $user_email; } /** * Array of all possible "in cart" gateways that can be offered. * * @return array */ protected function get_wizard_available_in_cart_payment_gateways() { $user_email = $this->get_current_user_email(); $stripe_description = '

' . sprintf( /* translators: %s: URL */ __( 'Accept debit and credit cards in 135+ currencies, methods such as Alipay, and one-touch checkout with Apple Pay. Learn more.', 'woocommerce' ), 'https://woocommerce.com/products/stripe/' ) . '

'; $paypal_ec_description = '

' . sprintf( /* translators: %s: URL */ __( 'Safe and secure payments using credit cards or your customer\'s PayPal account. Learn more.', 'woocommerce' ), 'https://woocommerce.com/products/woocommerce-gateway-paypal-express-checkout/' ) . '

'; $klarna_checkout_description = '

' . sprintf( /* translators: %s: URL */ __( 'Full checkout experience with pay now, pay later and slice it. No credit card numbers, no passwords, no worries. Learn more about Klarna.', 'woocommerce' ), 'https://woocommerce.com/products/klarna-checkout/' ) . '

'; $klarna_payments_description = '

' . sprintf( /* translators: %s: URL */ __( 'Choose the payment that you want, pay now, pay later or slice it. No credit card numbers, no passwords, no worries. Learn more about Klarna.', 'woocommerce' ), 'https://woocommerce.com/products/klarna-payments/ ' ) . '

'; $square_description = '

' . sprintf( /* translators: %s: URL */ __( 'Securely accept credit and debit cards with one low rate, no surprise fees (custom rates available). Sell online and in store and track sales and inventory in one place. Learn more about Square.', 'woocommerce' ), 'https://woocommerce.com/products/square/' ) . '

'; return array( 'stripe' => array( 'name' => __( 'Stripe', 'woocommerce' ), 'image' => WC()->plugin_url() . '/assets/images/stripe.png', 'description' => $stripe_description, 'class' => 'checked stripe-logo', 'repo-slug' => 'woocommerce-gateway-stripe', 'settings' => array( 'create_account' => array( 'label' => __( 'Create a new Stripe account for me', 'woocommerce' ), 'type' => 'checkbox', 'value' => 'yes', 'placeholder' => '', 'required' => false, ), 'email' => array( 'label' => __( 'Stripe email address:', 'woocommerce' ), 'type' => 'email', 'value' => $user_email, 'placeholder' => __( 'Stripe email address', 'woocommerce' ), 'description' => __( "Enter your email address and we'll handle account creation. WooCommerce Services and Jetpack will be installed and activated for you.", 'woocommerce' ), 'required' => true, ), ), ), 'ppec_paypal' => array( 'name' => __( 'PayPal Express Checkout', 'woocommerce' ), 'image' => WC()->plugin_url() . '/assets/images/paypal.png', 'description' => $paypal_ec_description, 'enabled' => true, 'class' => 'checked paypal-logo', 'repo-slug' => 'woocommerce-gateway-paypal-express-checkout', 'settings' => array( 'reroute_requests' => array( 'label' => __( 'Accept payments without linking a PayPal account', 'woocommerce' ), 'type' => 'checkbox', 'value' => 'yes', 'placeholder' => '', 'required' => false, ), 'email' => array( 'label' => __( 'Direct payments to email address:', 'woocommerce' ), 'type' => 'email', 'value' => $user_email, 'placeholder' => __( 'Email address to receive payments', 'woocommerce' ), 'description' => __( "Enter your email address and we'll authenticate payments for you. WooCommerce Services and Jetpack will be installed and activated for you.", 'woocommerce' ), 'required' => true, ), ), ), 'paypal' => array( 'name' => __( 'PayPal Standard', 'woocommerce' ), 'description' => __( 'Accept payments via PayPal using account balance or credit card.', 'woocommerce' ), 'image' => '', 'settings' => array( 'email' => array( 'label' => __( 'PayPal email address:', 'woocommerce' ), 'type' => 'email', 'value' => $user_email, 'placeholder' => __( 'PayPal email address', 'woocommerce' ), 'required' => true, ), ), ), 'klarna_checkout' => array( 'name' => __( 'Klarna Checkout', 'woocommerce' ), 'description' => $klarna_checkout_description, 'image' => WC()->plugin_url() . '/assets/images/klarna-white.png', 'enabled' => true, 'class' => 'klarna-logo', 'repo-slug' => 'klarna-checkout-for-woocommerce', ), 'klarna_payments' => array( 'name' => __( 'Klarna Payments', 'woocommerce' ), 'description' => $klarna_payments_description, 'image' => WC()->plugin_url() . '/assets/images/klarna-white.png', 'enabled' => true, 'class' => 'klarna-logo', 'repo-slug' => 'klarna-payments-for-woocommerce', ), 'square' => array( 'name' => __( 'Square', 'woocommerce' ), 'description' => $square_description, 'image' => WC()->plugin_url() . '/assets/images/square-white.png', 'class' => 'square-logo', 'enabled' => true, 'repo-slug' => 'woocommerce-square', ), ); } /** * Simple array of "in cart" gateways to show in wizard. * * @return array */ public function get_wizard_in_cart_payment_gateways() { $gateways = $this->get_wizard_available_in_cart_payment_gateways(); if ( ! current_user_can( 'install_plugins' ) ) { return array( 'paypal' => $gateways['paypal'] ); } $country = WC()->countries->get_base_country(); $can_stripe = $this->is_stripe_supported_country( $country ); if ( $this->is_klarna_checkout_supported_country( $country ) ) { $spotlight = 'klarna_checkout'; } elseif ( $this->is_klarna_payments_supported_country( $country ) ) { $spotlight = 'klarna_payments'; } elseif ( $this->is_square_supported_country( $country ) && get_option( 'woocommerce_sell_in_person' ) ) { $spotlight = 'square'; } if ( isset( $spotlight ) ) { $offered_gateways = array( $spotlight => $gateways[ $spotlight ], 'ppec_paypal' => $gateways['ppec_paypal'], ); if ( $can_stripe ) { $offered_gateways += array( 'stripe' => $gateways['stripe'] ); } return $offered_gateways; } $offered_gateways = array(); if ( $can_stripe ) { $gateways['stripe']['enabled'] = true; $gateways['stripe']['featured'] = true; $offered_gateways += array( 'stripe' => $gateways['stripe'] ); } $offered_gateways += array( 'ppec_paypal' => $gateways['ppec_paypal'] ); return $offered_gateways; } /** * Simple array of "manual" gateways to show in wizard. * * @return array */ protected function get_wizard_manual_payment_gateways() { $gateways = array( 'cheque' => array( 'name' => _x( 'Check payments', 'Check payment method', 'woocommerce' ), 'description' => __( 'A simple offline gateway that lets you accept a check as method of payment.', 'woocommerce' ), 'image' => '', 'class' => '', ), 'bacs' => array( 'name' => __( 'Bank transfer (BACS) payments', 'woocommerce' ), 'description' => __( 'A simple offline gateway that lets you accept BACS payment.', 'woocommerce' ), 'image' => '', 'class' => '', ), 'cod' => array( 'name' => __( 'Cash on delivery', 'woocommerce' ), 'description' => __( 'A simple offline gateway that lets you accept cash on delivery.', 'woocommerce' ), 'image' => '', 'class' => '', ), ); return $gateways; } /** * Display service item in list. * * @param int $item_id Item ID. * @param array $item_info Item info array. */ public function display_service_item( $item_id, $item_info ) { $item_class = 'wc-wizard-service-item'; if ( isset( $item_info['class'] ) ) { $item_class .= ' ' . $item_info['class']; } $previously_saved_settings = get_option( 'woocommerce_' . $item_id . '_settings' ); // Show the user-saved state if it was previously saved. // Otherwise, rely on the item info. if ( is_array( $previously_saved_settings ) ) { $should_enable_toggle = isset( $previously_saved_settings['enabled'] ) && 'yes' === $previously_saved_settings['enabled']; } else { $should_enable_toggle = isset( $item_info['enabled'] ) && $item_info['enabled']; } ?>
  • <?php echo esc_attr( $item_info['name'] ); ?>

    $setting ) : ?>
    />
    />
  • is_featured_service( $service ); } /** * Payment Step. */ public function wc_setup_payment() { $featured_gateways = array_filter( $this->get_wizard_in_cart_payment_gateways(), array( $this, 'is_featured_service' ) ); $in_cart_gateways = array_filter( $this->get_wizard_in_cart_payment_gateways(), array( $this, 'is_not_featured_service' ) ); $manual_gateways = $this->get_wizard_manual_payment_gateways(); ?>

    Additional payment methods can be installed later.', 'woocommerce' ), array( 'a' => array( 'href' => array(), 'target' => array(), ), ) ), esc_url( admin_url( 'admin.php?page=wc-addons§ion=payment-gateways' ) ) ); ?>

    install_woocommerce_services(); } $gateways = array_merge( $this->get_wizard_in_cart_payment_gateways(), $this->get_wizard_manual_payment_gateways() ); foreach ( $gateways as $gateway_id => $gateway ) { // If repo-slug is defined, download and install plugin from .org. if ( ! empty( $gateway['repo-slug'] ) && ! empty( $_POST[ 'wc-wizard-service-' . $gateway_id . '-enabled' ] ) ) { // WPCS: CSRF ok, input var ok. $this->install_plugin( $gateway_id, $gateway ); } $settings = array( 'enabled' => ! empty( $_POST[ 'wc-wizard-service-' . $gateway_id . '-enabled' ] ) ? 'yes' : 'no' ); // WPCS: CSRF ok, input var ok. // @codingStandardsIgnoreStart if ( ! empty( $gateway['settings'] ) ) { foreach ( $gateway['settings'] as $setting_id => $setting ) { $settings[ $setting_id ] = 'yes' === $settings['enabled'] && isset( $_POST[ $gateway_id . '_' . $setting_id ] ) ? wc_clean( wp_unslash( $_POST[ $gateway_id . '_' . $setting_id ] ) ) : false; } } // @codingStandardsIgnoreSEnd if ( 'ppec_paypal' === $gateway_id && empty( $settings['reroute_requests'] ) ) { unset( $settings['enabled'] ); } $settings_key = 'woocommerce_' . $gateway_id . '_settings'; $previously_saved_settings = array_filter( (array) get_option( $settings_key, array() ) ); update_option( $settings_key, array_merge( $previously_saved_settings, $settings ) ); } wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); exit; } /** * Extras. */ public function wc_setup_extras() { ?>

    should_show_theme_extra() ) : ?> should_show_automated_tax_extra() ) : ?>

    install_woocommerce_services(); } if ( $install_storefront ) { $this->install_theme( 'storefront' ); } wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); exit; } /** * Go to the next step if Jetpack was connected. */ protected function wc_setup_activate_actions() { if ( isset( $_GET['from'] ) && 'wpcom' === $_GET['from'] && class_exists( 'Jetpack' ) && Jetpack::is_active() ) { wp_redirect( esc_url_raw( remove_query_arg( 'from', $this->get_next_step_link() ) ) ); exit; } } protected function wc_setup_activate_get_feature_list() { $features = array(); $stripe_settings = get_option( 'woocommerce_stripe_settings', false ); $stripe_enabled = is_array( $stripe_settings ) && isset( $stripe_settings['create_account'] ) && 'yes' === $stripe_settings['create_account'] && isset( $stripe_settings['enabled'] ) && 'yes' === $stripe_settings['enabled']; $ppec_settings = get_option( 'woocommerce_ppec_paypal_settings', false ); $ppec_enabled = is_array( $ppec_settings ) && isset( $ppec_settings['reroute_requests'] ) && 'yes' === $ppec_settings['reroute_requests'] && isset( $ppec_settings['enabled'] ) && 'yes' === $ppec_settings['enabled']; $features['payment'] = $stripe_enabled || $ppec_enabled; $features['taxes'] = (bool) get_option( 'woocommerce_setup_automated_taxes', false ); $domestic_rates = (bool) get_option( 'woocommerce_setup_domestic_live_rates_zone', false ); $intl_rates = (bool) get_option( 'woocommerce_setup_intl_live_rates_zone', false ); $features['rates'] = $domestic_rates || $intl_rates; return $features; } protected function wc_setup_activate_get_feature_list_str() { $features = $this->wc_setup_activate_get_feature_list(); if ( $features['payment'] && $features['taxes'] && $features['rates'] ) { return __( 'payment setup, automated taxes, live rates and discounted shipping labels', 'woocommerce' ); } else if ( $features['payment'] && $features['taxes'] ) { return __( 'payment setup and automated taxes', 'woocommerce' ); } else if ( $features['payment'] && $features['rates'] ) { return __( 'payment setup, live rates and discounted shipping labels', 'woocommerce' ); } else if ( $features['payment'] ) { return __( 'payment setup', 'woocommerce' ); } else if ( $features['taxes'] && $features['rates'] ) { return __( 'automated taxes, live rates and discounted shipping labels', 'woocommerce' ); } else if ( $features['taxes'] ) { return __( 'automated taxes', 'woocommerce' ); } else if ( $features['rates'] ) { return __( 'live rates and discounted shipping labels', 'woocommerce' ); } return false; } /** * Activate step. */ public function wc_setup_activate() { $this->wc_setup_activate_actions(); $jetpack_connected = class_exists( 'Jetpack' ) && Jetpack::is_active(); $has_jetpack_error = false; if ( isset( $_GET['activate_error'] ) ) { $has_jetpack_error = true; $title = __( "Sorry, we couldn't connect your store to Jetpack", 'woocommerce' ); $error_message = $this->get_activate_error_message( sanitize_text_field( wp_unslash( $_GET['activate_error'] ) ) ); $description = $error_message; } else { $feature_list = $this->wc_setup_activate_get_feature_list_str(); $description = false; if ( $feature_list ) { if ( ! $jetpack_connected ) { /* translators: %s: list of features, potentially comma separated */ $description_base = __( 'Your store is almost ready! To activate services like %s, just connect with Jetpack.', 'woocommerce' ); } else { $description_base = __( 'Thanks for using Jetpack! Your store is almost ready: to activate services like %s, just connect your store.', 'woocommerce' ); } $description = sprintf( $description_base, $feature_list ); } if ( ! $jetpack_connected ) { $title = $feature_list ? __( 'Connect your store to Jetpack', 'woocommerce' ) : __( 'Connect your store to Jetpack to enable extra features', 'woocommerce' ); $button_text = __( 'Continue with Jetpack', 'woocommerce' ); } elseif ( $feature_list ) { $title = __( 'Connect your store to activate WooCommerce Services', 'woocommerce' ); $button_text = __( 'Continue with WooCommerce Services', 'woocommerce' ); } else { wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); exit; } } ?>

    Terms of Service and to share details with WordPress.com', 'woocommerce' ) ), 'https://wordpress.com/tos', 'https://jetpack.com/support/what-data-does-jetpack-sync' ); ?>

    __( "Sorry! We tried, but we couldn't connect Jetpack just now ๐Ÿ˜ญ. Please go to the Plugins tab to connect Jetpack, so that you can finish setting up your store.", 'woocommerce' ), 'jetpack_cant_be_installed' => __( "Sorry! We tried, but we couldn't install Jetpack for you ๐Ÿ˜ญ. Please go to the Plugins tab to install it, and finish setting up your store.", 'woocommerce' ), 'register_http_request_failed' => __( "Sorry! We couldn't contact Jetpack just now ๐Ÿ˜ญ. Please make sure that your site is visible over the internet, and that it accepts incoming and outgoing requests via curl. You can also try to connect to Jetpack again, and if you run into any more issues, please contact support.", 'woocommerce' ), 'siteurl_private_ip_dev' => __( "Your site might be on a private network. Jetpack can only connect to public sites. Please make sure your site is visible over the internet, and then try connecting again ๐Ÿ™." , 'woocommerce' ), ); } protected function get_activate_error_message( $code = '' ) { $errors = $this->get_all_activate_errors(); return array_key_exists( $code, $errors ) ? $errors[ $code ] : $errors['default']; } /** * Activate step save. * * Install, activate, and launch connection flow for Jetpack. */ public function wc_setup_activate_save() { check_admin_referer( 'wc-setup' ); set_transient( 'wc_setup_activated', 'yes', MINUTE_IN_SECONDS * 10 ); // Leave a note for WooCommerce Services that Jetpack has been opted into. update_option( 'woocommerce_setup_jetpack_opted_in', true ); if ( class_exists( 'Jetpack' ) && Jetpack::is_active() ) { wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) ); exit; } WC_Install::background_installer( 'jetpack', array( 'file' => 'jetpack/jetpack.php', 'name' => __( 'Jetpack', 'woocommerce' ), 'repo-slug' => 'jetpack', ) ); // Did Jetpack get successfully installed? if ( ! class_exists( 'Jetpack' ) ) { wp_redirect( esc_url_raw( add_query_arg( 'activate_error', 'jetpack_cant_be_installed' ) ) ); exit; } Jetpack::maybe_set_version_option(); $register_result = Jetpack::try_registration(); if ( is_wp_error( $register_result ) ) { $result_error_code = $register_result->get_error_code(); $jetpack_error_code = array_key_exists( $result_error_code, $this->get_all_activate_errors() ) ? $result_error_code : 'register'; wp_redirect( esc_url_raw( add_query_arg( 'activate_error', $jetpack_error_code ) ) ); exit; } $redirect_url = esc_url_raw( add_query_arg( array( 'page' => 'wc-setup', 'step' => 'activate', 'from' => 'wpcom', 'activate_error' => false, ), admin_url() ) ); $connection_url = Jetpack::init()->build_connect_url( true, $redirect_url, 'woocommerce-setup-wizard' ); wp_redirect( esc_url_raw( $connection_url ) ); exit; } /** * Final step. */ public function wc_setup_ready() { // We've made it! Don't prompt the user to run the wizard again. WC_Admin_Notices::remove_notice( 'install' ); $user_email = $this->get_current_user_email(); $videos_url = 'https://docs.woocommerce.com/document/woocommerce-guided-tour-videos/?utm_source=setupwizard&utm_medium=product&utm_content=videos&utm_campaign=woocommerceplugin'; $docs_url = 'https://docs.woocommerce.com/documentation/plugins/woocommerce/getting-started/?utm_source=setupwizard&utm_medium=product&utm_content=docs&utm_campaign=woocommerceplugin'; $help_text = sprintf( /* translators: %1$s: link to videos, %2$s: link to docs */ __( 'Watch our guided tour videos to learn more about WooCommerce, and visit WooCommerce.com to learn more about getting started.', 'woocommerce' ), $videos_url, $docs_url ); ?>