array(
'name' => __( 'Store setup', 'woocommerce' ),
'view' => array( $this, 'wc_setup_store_setup' ),
'handler' => array( $this, 'wc_setup_store_setup_save' ),
),
'payments' => array(
'name' => __( 'Payments', 'woocommerce' ),
'view' => array( $this, 'wc_setup_payments' ),
'handler' => array( $this, 'wc_setup_payments_save' ),
),
'shipping' => array(
'name' => __( 'Shipping', 'woocommerce' ),
'view' => array( $this, 'wc_setup_shipping' ),
'handler' => array( $this, 'wc_setup_shipping_save' ),
),
'theme' => array(
'name' => __( 'Theme', 'woocommerce' ),
'view' => array( $this, 'wc_setup_theme' ),
'handler' => array( $this, 'wc_setup_theme_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 storefront step if using a WooCommerce theme or user cannot modify themes.
if ( ! current_user_can( 'install_themes' ) || ! current_user_can( 'switch_themes' ) || is_multisite() || current_theme_supports( 'woocommerce' ) ) {
unset( $default_steps['theme'] );
}
// Hide shipping step if the store is selling digital products only.
if ( 'virtual' === get_option( 'woocommerce_product_type' ) ) {
unset( $default_steps['shipping'] );
}
$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' ), WC_VERSION );
wp_localize_script( 'wc-setup', 'wc_setup_params', array(
'locale_info' => json_encode( include( WC()->plugin_path() . '/i18n/locale-info.php' ) ),
) );
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 ] );
}
/**
* Setup Wizard Header.
*/
public function setup_wizard_header() {
?>
>
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'];
}
?>
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 );
?>
install_plugin( 'jetpack', array(
'file' => 'jetpack/jetpack.php',
'name' => __( 'Jetpack', 'woocommerce' ),
'repo-slug' => 'jetpack',
), ! $now );
}
/**
* 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',
) );
}
/**
* Shipping.
*/
public function wc_setup_shipping() {
$dimension_unit = get_option( 'woocommerce_dimension_unit', false );
$weight_unit = get_option( 'woocommerce_weight_unit', false );
if ( false === $dimension_unit || false === $weight_unit ) {
$country = get_option( 'woocommerce_default_country', '' );
if ( 0 === strpos( $country, 'US:' ) ) {
$dimension_unit = 'in';
$weight_unit = 'oz';
} else {
$dimension_unit = 'cm';
$weight_unit = 'kg';
}
}
?>
get_next_step_link() ) );
exit;
}
$current_shipping = get_option( 'woocommerce_ship_to_countries' );
$install_services = isset( $_POST['woocommerce_install_services'] );
$weight_unit = sanitize_text_field( $_POST['weight_unit'] );
$dimension_unit = sanitize_text_field( $_POST['dimension_unit'] );
update_option( 'woocommerce_ship_to_countries', '' );
update_option( 'woocommerce_weight_unit', $weight_unit );
update_option( 'woocommerce_dimension_unit', $dimension_unit );
/*
* If this is the initial shipping setup, create a shipping
* zone containing the country the store is located in, with
* a "free shipping" method preconfigured.
*/
if ( false === $current_shipping ) {
$default_country = get_option( 'woocommerce_default_country' );
$location = wc_format_country_state_string( $default_country );
$zone = new WC_Shipping_Zone( null );
$zone->set_zone_order( 0 );
$zone->add_location( $location['country'], 'country' );
$zone->set_zone_name( $zone->get_formatted_location() );
$zone->add_shipping_method( 'free_shipping' );
$zone->save();
}
if ( $install_services ) {
$this->install_woocommerce_services();
} else {
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' => __( 'Australia', 'woocommerce' ),
'AT' => __( 'Austria', 'woocommerce' ),
'BE' => __( 'Belgium', 'woocommerce' ),
'CA' => __( 'Canada', 'woocommerce' ),
'DK' => __( 'Denmark', 'woocommerce' ),
'FI' => __( 'Finland', 'woocommerce' ),
'FR' => __( 'France', 'woocommerce' ),
'DE' => __( 'Germany', 'woocommerce' ),
'HK' => __( 'Hong Kong', 'woocommerce' ),
'IE' => __( 'Ireland', 'woocommerce' ),
'JP' => __( 'Japan', 'woocommerce' ),
'LU' => __( 'Luxembourg', 'woocommerce' ),
'NL' => __( 'Netherlands', 'woocommerce' ),
'NZ' => __( 'New Zealand', 'woocommerce' ),
'NO' => __( 'Norway', 'woocommerce' ),
'SG' => __( 'Singapore', 'woocommerce' ),
'ES' => __( 'Spain', 'woocommerce' ),
'SE' => __( 'Sweden', 'woocommerce' ),
'CH' => __( 'Switzerland', 'woocommerce' ),
'GB' => __( 'United Kingdom (UK)', 'woocommerce' ),
'US' => __( 'United States (US)', 'woocommerce' ),
);
return array_key_exists( $country_code, $stripe_supported_countries );
}
/**
* 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 );
$gateways = array(
'stripe' => array(
'name' => __( 'Stripe', 'woocommerce' ),
'image' => WC()->plugin_url() . '/assets/images/stripe.png',
'description' => sprintf( __( 'Accept all major debit and credit cards from customers in 135+ countries on your site. Learn more about Stripe.
Fee: 2.9%% + 30¢ per transaction
', 'woocommerce' ), 'https://wordpress.org/plugins/woocommerce-gateway-stripe/' ),
'class' => $can_stripe ? 'checked' : '',
'repo-slug' => 'woocommerce-gateway-stripe',
'settings' => array(
'email' => array(
'label' => __( 'Stripe email address', 'woocommerce' ),
'type' => 'email',
'value' => get_option( 'admin_email' ),
'placeholder' => __( 'Stripe email address', 'woocommerce' ),
),
),
'enabled' => $can_stripe,
'featured' => true,
),
'braintree_paypal' => array(
'name' => __( 'PayPal by Braintree', 'woocommerce' ),
'image' => WC()->plugin_url() . '/assets/images/paypal-braintree.png',
'description' => __( "Safe and secure payments using credit cards or your customer's PayPal account.", 'woocommerce' ) . ' ' . __( 'Learn more about PayPal', 'woocommerce' ) . '.',
'class' => 'in-cart',
'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' => __( "Safe and secure payments using credit cards or your customer's PayPal account.", 'woocommerce' ) . ' ' . __( 'Learn more about PayPal', 'woocommerce' ) . '',
'class' => 'in-cart',
'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' => '',
'class' => 'in-cart',
'settings' => array(
'email' => array(
'label' => __( 'PayPal email address', 'woocommerce' ),
'type' => 'email',
'value' => get_option( 'admin_email' ),
'placeholder' => __( 'PayPal email address', 'woocommerce' ),
),
),
),
);
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 ) {
$enabled = isset( $item_info['enabled'] ) && $item_info['enabled'];
?>
/>
is_featured_service( $service );
}
/**
* Payments Step.
*/
public function wc_setup_payments() {
$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();
$country = WC()->countries->get_base_country();
$can_stripe = $this->is_stripe_supported_country( $country );
?>
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 ] = wc_clean( $_POST[ $gateway_id . '_' . $setting_id ] );
}
}
update_option( $settings_key, $settings );
}
// Install WooCommerce Services with Stripe to enable deferred account creation
if ( ! empty( $_POST[ 'wc-wizard-service-stripe-enabled' ] ) ) {
$this->install_woocommerce_services();
}
wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
exit;
}
/**
* Theme step.
*/
private function wc_setup_theme() {
?>
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;
}
}
/**
* Activate step.
*/
public function wc_setup_activate() {
$this->wc_setup_activate_actions();
?>
install_jetpack( true );
if ( ! class_exists( 'Jetpack' ) ) {
wp_redirect( esc_url_raw( add_query_arg( 'error', true ) ) );
exit;
}
$redirect_url = site_url( add_query_arg( 'from', 'wpcom' ) );
$connection_url = Jetpack::init()->build_connect_url( true, $redirect_url, 'woocommerce' );
wp_redirect( esc_url_raw( $connection_url ) );
exit;
}
/**
* Actions on the final step.
*/
private function wc_setup_ready_actions() {
WC_Admin_Notices::remove_notice( 'install' );
if ( isset( $_GET['wc_tracker_optin'] ) && isset( $_GET['wc_tracker_nonce'] ) && wp_verify_nonce( $_GET['wc_tracker_nonce'], 'wc_tracker_optin' ) ) {
update_option( 'woocommerce_allow_tracking', 'yes' );
WC_Tracker::send_tracking_data( true );
} elseif ( isset( $_GET['wc_tracker_optout'] ) && isset( $_GET['wc_tracker_nonce'] ) && wp_verify_nonce( $_GET['wc_tracker_nonce'], 'wc_tracker_optout' ) ) {
update_option( 'woocommerce_allow_tracking', 'no' );
}
}
/**
* Final step.
*/
public function wc_setup_ready() {
$this->wc_setup_ready_actions();
$current_user = wp_get_current_user();
shuffle( $this->tweets );
?>