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() { 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 ); } /** * Should we show the MailChimp install option? * True only if the user can install plugins. * * @return boolean */ protected function should_show_mailchimp() { return current_user_can( 'install_plugins' ); } /** * Should we display the 'Recommended' step? * True if at least one of the recommendations will be displayed. * * @return boolean */ protected function should_show_recommended_step() { return $this->should_show_theme() || $this->should_show_automated_tax() || $this->should_show_mailchimp(); } /** * 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' ), ), 'recommended' => array( 'name' => __( 'Recommended', 'woocommerce' ), 'view' => array( $this, 'wc_setup_recommended' ), 'handler' => array( $this, 'wc_setup_recommended_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 recommended step if nothing is going to be shown there. if ( ! $this->should_show_recommended_step() ) { unset( $default_steps['recommended'] ); } // 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', 'states' => WC()->countries->get_states(), ) ); // @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() { ?> >
' . 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' => __( 'WooCommerce Stripe Gateway', '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, 'plugins' => $this->get_wcs_requisite_plugins(), ), '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. Powered by WooCommerce Services and Jetpack.", 'woocommerce' ), 'required' => true, ), ), ), 'ppec_paypal' => array( 'name' => __( 'WooCommerce PayPal Express Checkout Gateway', '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, 'plugins' => $this->get_wcs_requisite_plugins(), ), '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. Powered by WooCommerce Services and Jetpack.", '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 for WooCommerce', '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 for WooCommerce', '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' => __( 'WooCommerce Square', 'woocommerce' ), 'description' => $square_description, 'image' => WC()->plugin_url() . '/assets/images/square-white.png', 'class' => 'square-logo', 'enabled' => true, 'repo-slug' => 'woocommerce-square', ), 'eway' => array( 'name' => __( 'WooCommerce eWAY Gateway', 'woocommerce' ), 'description' => __( 'The eWAY extension for WooCommerce allows you to take credit card payments directly on your store without redirecting your customers to a third party site to make payment.', 'woocommerce' ), 'image' => WC()->plugin_url() . '/assets/images/eway-logo.jpg', 'enabled' => false, 'class' => 'eway-logo', 'repo-slug' => 'woocommerce-gateway-eway', ), 'payfast' => array( 'name' => __( 'WooCommerce PayFast Gateway', 'woocommerce' ), 'description' => __( 'The PayFast extension for WooCommerce enables you to accept payments by Credit Card and EFT via one of South Africa’s most popular payment gateways. No setup fees or monthly subscription costs.', 'woocommerce' ), 'image' => WC()->plugin_url() . '/assets/images/payfast.png', 'class' => 'payfast-logo', 'enabled' => false, 'repo-slug' => 'woocommerce-payfast-gateway', 'file' => 'gateway-payfast.php', ), ); } /** * 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(); $country = WC()->countries->get_base_country(); $currency = get_woocommerce_currency(); $can_stripe = $this->is_stripe_supported_country( $country ); $can_eway = $this->is_eway_payments_supported_country( $country ); $can_payfast = ( 'ZA' === $country ); // South Africa. $can_paypal = $this->is_paypal_supported_currency( $currency ); if ( ! current_user_can( 'install_plugins' ) ) { return $can_paypal ? array( 'paypal' => $gateways['paypal'] ) : array(); } $spotlight = ''; 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 ( $spotlight ) { $offered_gateways = array( $spotlight => $gateways[ $spotlight ], ); if ( $can_paypal ) { $offered_gateways += array( 'ppec_paypal' => $gateways['ppec_paypal'] ); } if ( $can_stripe ) { $offered_gateways += array( 'stripe' => $gateways['stripe'] ); } if ( $can_eway ) { $offered_gateways += array( 'eway' => $gateways['eway'] ); } if ( $can_payfast ) { $offered_gateways += array( 'payfast' => $gateways['payfast'] ); } return $offered_gateways; } $offered_gateways = array(); if ( $can_stripe ) { $gateways['stripe']['enabled'] = true; $gateways['stripe']['featured'] = true; $offered_gateways += array( 'stripe' => $gateways['stripe'] ); } if ( $can_paypal ) { $offered_gateways += array( 'ppec_paypal' => $gateways['ppec_paypal'] ); } if ( $can_eway ) { $offered_gateways += array( 'eway' => $gateways['eway'] ); } if ( $can_payfast ) { $offered_gateways += array( 'payfast' => $gateways['payfast'] ); } 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']; } $plugins = null; if ( isset( $item_info['repo-slug'] ) ) { $plugin = array( 'slug' => $item_info['repo-slug'], 'name' => $item_info['name'], ); $plugins = array( $plugin ); } ?>should_show_theme() && $this->should_show_automated_tax() && $this->should_show_mailchimp() ) : esc_html_e( 'Select from the list below to enable automated taxes and MailChimp’s best-in-class email services — and design your store with our official, free WooCommerce theme.', 'woocommerce' ); else : esc_html_e( 'Enhance your store with these recommended features.', 'woocommerce' ); endif; ?>
install_theme( 'storefront' ); } if ( $setup_automated_tax ) { $this->install_woocommerce_services(); } if ( $setup_mailchimp ) { // Prevent MailChimp from redirecting to its settings page during the OBW flow. add_option( 'mailchimp_woocommerce_plugin_do_activation_redirect', false ); $this->install_plugin( 'mailchimp-for-woocommerce', array( 'name' => __( 'MailChimp for WooCommerce', 'woocommerce' ), 'repo-slug' => 'mailchimp-for-woocommerce', 'file' => 'mailchimp-woocommerce.php', ) ); } 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' ); ?>