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 ); } /** * Show the setup wizard. */ public function setup_wizard() { if ( empty( $_GET['page'] ) || 'wc-setup' !== $_GET['page'] ) { 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'] ); } // Hide the activate step if Jetpack is already active, but not // if we're returning from connecting Jetpack on WordPress.com. if ( class_exists( 'Jetpack' ) && Jetpack::is_active() && ! isset( $_GET['from'] ) && ! isset( $_GET['activate_error'] ) ) { unset( $default_steps['activate'] ); } // 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 ) ); $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', ) ); if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) { call_user_func( $this->steps[ $this->step ]['handler'], $this ); } 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 ); 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 ) : ?> step ) : ?> steps; ?>
    $step ) : ?>
'; 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' ); if ( empty( $country ) ) { $user_location = WC_Geolocation::geolocate_ip(); $country = $user_location['country']; $state = $user_location['state']; } elseif ( empty( $state ) ) { $state = '*'; } ?>

" name="save_step" />

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_redirect( esc_url_raw( $this->get_next_step_link() ) ); exit; } /** * Tout WooCommerce Services for North American stores. */ protected function wc_setup_wcs_tout() { $base_location = wc_get_base_location(); if ( false === $base_location['country'] ) { $base_location = WC_Geolocation::geolocate_ip(); } if ( ! in_array( $base_location['country'], array( 'US', 'CA' ), true ) ) { return; } $default_content = array( 'title' => __( 'Enable WooCommerce Shipping (recommended)', 'woocommerce' ), 'description' => __( 'Print labels and get discounted USPS shipping rates, right from your WooCommerce dashboard. Powered by WooCommerce Services.', 'woocommerce' ), ); switch ( $base_location['country'] ) { case 'CA': $local_content = array( 'title' => __( 'Enable WooCommerce Shipping (recommended)', 'woocommerce' ), 'description' => __( 'Display live rates from Canada Post at checkout to make shipping a breeze. Powered by WooCommerce Services.', 'woocommerce' ), ); break; default: $local_content = array(); } $content = wp_parse_args( $local_content, $default_content ); ?> 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 $country_code * @return bool|string Carrier name if supported, boolean False otherwise. */ protected function get_wcs_shipping_carrier( $country_code ) { switch ( $country_code ) { case 'US': return 'USPS'; case 'CA': return 'Canada Post'; default: return false; } } /** * Get shipping methods based on country code. * * @param $country_code * @return array */ protected function get_wizard_shipping_methods( $country_code ) { $shipping_methods = array( 'live_rates' => array( 'name' => __( 'Live Rates', 'woocommerce' ), 'description' => __( 'Shipping rates updated in realtime. Powered by Jetpack.', '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', 'Short label for entering the cost of an item', '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 ); 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 * @param string $input_prefix */ protected function shipping_method_selection_form( $country_code, $input_prefix ) { $live_rate_carrier = $this->get_wcs_shipping_carrier( $country_code ); $selected = $live_rate_carrier ? 'live_rates' : 'flat_rate'; $shipping_methods = $this->get_wizard_shipping_methods( $country_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; $wcs_carrier = $this->get_wcs_shipping_carrier( $country_code ); $existing_zones = WC_Shipping_Zones::get_zones(); if ( false === $dimension_unit || false === $weight_unit ) { if ( 'US' === $country_code ) { $dimension_unit = 'in'; $weight_unit = 'oz'; } else { $dimension_unit = 'cm'; $weight_unit = 'kg'; } } 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 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 ] ) ) { $method_controller = new WC_REST_Shipping_Zone_Methods_Controller(); $method_controller->update_item( array( 'zone_id' => $zone->get_id(), 'instance_id' => $instance_id, 'settings' => $_POST['shipping_zones']['domestic'][ $domestic_method ], ) ); } } // 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 ] ) ) { $method_controller = new WC_REST_Shipping_Zone_Methods_Controller(); $method_controller->update_item( array( 'zone_id' => $zone->get_id(), 'instance_id' => $instance_id, 'settings' => $_POST['shipping_zones']['intl'][ $intl_method ], ) ); } } // Notify the user that no shipping methods are configured. if ( ! $setup_domestic && ! $setup_intl ) { WC_Admin_Notices::add_notice( 'no_shipping_methods' ); } wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); exit; } /** * https://stripe.com/global */ 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 ); } /** * 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; } /** * Simple array of "in cart" gateways to show in wizard. * @return array */ protected function get_wizard_in_cart_payment_gateways() { $country = WC()->countries->get_base_country(); $can_stripe = $this->is_stripe_supported_country( $country ); $user_email = $this->get_current_user_email(); $stripe_description = '

' . sprintf( __( 'Accept all major debit and credit cards from customers in 135+ countries on your site. Learn more.', 'woocommerce' ), 'https://wordpress.org/plugins/woocommerce-gateway-stripe/' ) . '

'; $paypal_bt_description = '

' . sprintf( __( 'Safe and secure payments using credit cards or your customer\'s PayPal account. Learn more.', 'woocommerce' ), 'https://wordpress.org/plugins/woocommerce-gateway-paypal-powered-by-braintree/' ) . '

'; $paypal_ec_description = '

' . sprintf( __( 'Safe and secure payments using credit cards or your customer\'s PayPal account. Learn more.', 'woocommerce' ), 'https://wordpress.org/plugins/woocommerce-gateway-paypal-express-checkout/' ) . '

'; $gateways = array( 'stripe' => array( 'name' => __( 'Stripe', 'woocommerce' ), 'image' => WC()->plugin_url() . '/assets/images/stripe.png', 'description' => $stripe_description, 'class' => $can_stripe ? 'checked' : '', 'repo-slug' => 'woocommerce-gateway-stripe', 'settings' => array( 'create_account' => array( 'label' => __( 'Create an account for me using this email:', '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' ), 'required' => true, ), ), 'enabled' => $can_stripe, 'featured' => true, ), 'braintree_paypal' => array( 'name' => __( 'PayPal by Braintree', 'woocommerce' ), 'image' => WC()->plugin_url() . '/assets/images/paypal-braintree.png', 'description' => $paypal_bt_description, 'repo-slug' => 'woocommerce-gateway-paypal-powered-by-braintree', ), 'ppec_paypal' => array( 'name' => __( 'PayPal Express Checkout', 'woocommerce' ), 'image' => WC()->plugin_url() . '/assets/images/paypal.png', 'description' => $paypal_ec_description, 'repo-slug' => 'woocommerce-gateway-paypal-express-checkout', ), '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, ), ), ), ); if ( ! $can_stripe ) { unset( $gateways['stripe'] ); } if ( 'US' === $country ) { unset( $gateways['ppec_paypal'] ); } else { unset( $gateways['braintree_paypal'] ); } if ( ! current_user_can( 'install_plugins' ) ) { unset( $gateways['braintree_paypal'] ); unset( $gateways['ppec_paypal'] ); unset( $gateways['stripe'] ); } return $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. */ 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 = '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' ), esc_url( admin_url( 'admin.php?page=wc-addons&view=payment-gateways' ) ) ); ?>

    install_woocommerce_services(); } $gateways = $this->get_wizard_in_cart_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' ] ) ) { $this->install_plugin( $gateway_id, $gateway ); } $settings_key = 'woocommerce_' . $gateway_id . '_settings'; $settings = array_filter( (array) get_option( $settings_key, array() ) ); $settings['enabled'] = ! empty( $_POST[ 'wc-wizard-service-' . $gateway_id . '-enabled' ] ) ? 'yes' : 'no'; if ( ! empty( $gateway['settings'] ) ) { foreach ( $gateway['settings'] as $setting_id => $setting ) { $settings[ $setting_id ] = 'yes' === $settings['enabled'] ? wc_clean( $_POST[ $gateway_id . '_' . $setting_id ] ) : false; } } update_option( $settings_key, $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_description() { $description = false; $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']; $taxes_enabled = (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 ); $rates_enabled = $domestic_rates || $intl_rates; /* 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' ); if ( $stripe_enabled && $taxes_enabled && $rates_enabled ) { $description = sprintf( $description_base, __( 'Stripe payments, automated taxes, live rates and discounted shipping labels', 'woocommerce' ) ); } else if ( $stripe_enabled && $taxes_enabled ) { $description = sprintf( $description_base, __( 'Stripe payments and automated taxes', 'woocommerce' ) ); } else if ( $stripe_enabled && $rates_enabled ) { $description = sprintf( $description_base, __( 'Stripe payments, live rates and discounted shipping labels', 'woocommerce' ) ); } else if ( $stripe_enabled ) { $description = sprintf( $description_base, __( 'Stripe payments', 'woocommerce' ) ); } else if ( $taxes_enabled && $rates_enabled ) { $description = sprintf( $description_base, __( 'automated taxes, live rates and discounted shipping labels', 'woocommerce' ) ); } else if ( $taxes_enabled ) { $description = sprintf( $description_base, __( 'automated taxes', 'woocommerce' ) ); } else if ( $rates_enabled ) { $description = sprintf( $description_base, __( 'live rates and discounted shipping labels', 'woocommerce' ) ); } return $description; } /** * Activate step. */ public function wc_setup_activate() { $this->wc_setup_activate_actions(); $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 { $description = $this->wc_setup_activate_get_description(); $title = $description ? __( 'Connect your store to Jetpack', 'woocommerce' ) : __( 'Connect your store to Jetpack to enable extra features', 'woocommerce' ); } ?>

    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' ); // Leave a note for WooCommerce Services that Jetpack has been opted into. update_option( 'woocommerce_setup_jetpack_opted_in', true ); 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 = site_url( add_query_arg( array( 'from' => 'wpcom', 'activate_error' => false, ) ) ); $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.' ), $videos_url, $docs_url ); ?>