tweets ); } } /** * Add admin menus/screens. */ public function admin_menus() { add_dashboard_page( '', '', 'manage_options', 'wc-setup', '' ); } /** * Show the setup wizard */ public function setup_wizard() { if ( empty( $_GET['page'] ) || 'wc-setup' !== $_GET['page'] ) { return; } $this->steps = array( 'introduction' => array( 'name' => __( 'Introduction', 'woocommerce' ), 'view' => array( $this, 'wc_setup_introduction' ), 'handler' => '' ), 'pages' => array( 'name' => __( 'Page Setup', 'woocommerce' ), 'view' => array( $this, 'wc_setup_pages' ), 'handler' => array( $this, 'wc_setup_pages_save' ) ), 'locale' => array( 'name' => __( 'Store Locale', 'woocommerce' ), 'view' => array( $this, 'wc_setup_locale' ), 'handler' => array( $this, 'wc_setup_locale_save' ) ), 'shipping_taxes' => array( 'name' => __( 'Shipping & Tax', 'woocommerce' ), 'view' => array( $this, 'wc_setup_shipping_taxes' ), 'handler' => array( $this, 'wc_setup_shipping_taxes_save' ), ), 'next_steps' => array( 'name' => __( 'Ready!', 'woocommerce' ), 'view' => array( $this, 'wc_setup_ready' ), 'handler' => '' ) ); $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) ); $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; wp_register_script( 'select2', WC()->plugin_url() . '/assets/js/select2/select2' . $suffix . '.js', array( 'jquery' ), '3.5.2' ); wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'select2' ), WC_VERSION ); wp_localize_script( 'wc-enhanced-select', 'wc_enhanced_select_params', array( 'i18n_matches_1' => _x( 'One result is available, press enter to select it.', 'enhanced select', 'woocommerce' ), 'i18n_matches_n' => _x( '%qty% results are available, use up and down arrow keys to navigate.', 'enhanced select', 'woocommerce' ), '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.min.js', array( 'jquery', 'wc-enhanced-select' ), 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'] ); } ob_start(); $this->setup_wizard_header(); $this->setup_wizard_steps(); $this->setup_wizard_content(); $this->setup_wizard_footer(); exit; } public function get_next_step_link() { $keys = array_keys( $this->steps ); return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ] ); } /** * Setup Wizard Header */ public function setup_wizard_header() { ?> > <?php _e( 'WooCommerce › Setup Wizard', 'woocommerce' ); ?>

WooCommerce

    steps as $step_key => $step ) : ?>
'; call_user_func( $this->steps[ $this->step ]['view'] ); echo ''; } /** * Introduction step */ public function wc_setup_introduction() { ?>

name="woocommerce_enable_guest_checkout" id="woocommerce_enable_guest_checkout" />

name="woocommerce_enable_signup_and_login_from_checkout" id="woocommerce_enable_signup_and_login_from_checkout" />

name="woocommerce_enable_myaccount_registration" id="woocommerce_enable_myaccount_registration" />

Menus screen%s.', 'woocommerce' ), '', '', '', '' ); ?>

get_next_step_link() ); exit; } /** * Locale settings */ public function wc_setup_locale() { $user_location = WC_Geolocation::geolocate_ip(); $country = ! empty( $user_location['country'] ) ? $user_location['country'] : 'US'; $state = ! empty( $user_location['state'] ) ? $user_location['state'] : '*'; $state = 'US' === $country && '*' === $state ? 'AL' : $state; // Defaults $currency = get_option( 'woocommerce_currency', 'GBP' ); $currency_pos = get_option( 'woocommerce_currency_pos', 'left' ); $decimal_sep = get_option( 'woocommerce_decimal_sep', '.' ); $thousand_sep = get_option( 'woocommerce_thousand_sep', ',' ); $dimension_unit = get_option( 'woocommerce_dimension_unit', 'cm' ); $weight_unit = get_option( 'woocommerce_weight_unit', 'kg' ); ?>

', '' ); ?>

get_next_step_link() ); exit; } /** * Shipping and taxes */ public function wc_setup_shipping_taxes() { $domestic = new WC_Shipping_Flat_Rate(); $international = new WC_Shipping_International_Delivery(); $shipping_cost_domestic = ''; $shipping_cost_domestic_item = ''; $shipping_cost_international = ''; $shipping_cost_international_item = ''; if ( 'yes' === $domestic->get_option( 'enabled' ) ) { $shipping_cost_domestic = $domestic->get_option( 'cost_per_order' ); $shipping_cost_domestic_item = $domestic->get_option( 'cost' ); } if ( 'yes' === $international->get_option( 'enabled' ) ) { $shipping_cost_international = $international->get_option( 'cost_per_order' ); $shipping_cost_international_item = $international->get_option( 'cost' ); } ?>

', '', '' ); ?>

plugin_path() . '/i18n/locale-info.php' ); $tax_rates = false; if ( isset( $locale_info[ WC()->countries->get_base_country() ] ) ) { if ( isset( $locale_info[ WC()->countries->get_base_country() ]['tax_rates'][ WC()->countries->get_base_state() ] ) ) { $tax_rates = $locale_info[ WC()->countries->get_base_country() ]['tax_rates'][ WC()->countries->get_base_state() ]; } elseif ( isset( $locale_info[ WC()->countries->get_base_country() ]['tax_rates'][''] ) ) { $tax_rates = $locale_info[ WC()->countries->get_base_country() ]['tax_rates']['']; } } if ( $tax_rates ) { ?>

name="woocommerce_calc_shipping" class="input-checkbox" value="1" />
', get_woocommerce_currency_symbol() . ' ' ); ?>
', get_woocommerce_currency_symbol() . ' ' ); ?>

id="woocommerce_calc_taxes" name="woocommerce_calc_taxes" class="input-checkbox" value="1" />

', '', '' ); ?>

settings['enabled'] = 'yes'; $shipping_method->settings['type'] = 'item'; $shipping_method->settings['cost_per_order'] = woocommerce_format_decimal( sanitize_text_field( $_POST['shipping_cost_domestic'] ) ); $shipping_method->settings['cost'] = woocommerce_format_decimal( sanitize_text_field( $_POST['shipping_cost_domestic_item'] ) ); $shipping_method->settings['fee'] = ''; update_option( $shipping_method->plugin_id . $shipping_method->id . '_settings', $shipping_method->settings ); } if ( 'yes' === $woocommerce_calc_shipping && ! empty( $_POST['shipping_cost_international'] ) ) { // Delete existing settings if they exist delete_option( 'woocommerce_international_delivery_flat_rates' ); delete_option( 'woocommerce_international_delivery_settings' ); // Init rate and settings $shipping_method = new WC_Shipping_International_Delivery(); $shipping_method->settings['enabled'] = 'yes'; $shipping_method->settings['type'] = 'item'; $shipping_method->settings['cost_per_order'] = woocommerce_format_decimal( sanitize_text_field( $_POST['shipping_cost_international'] ) ); $shipping_method->settings['cost'] = woocommerce_format_decimal( sanitize_text_field( $_POST['shipping_cost_international_item'] ) ); $shipping_method->settings['fee'] = ''; update_option( $shipping_method->plugin_id . $shipping_method->id . '_settings', $shipping_method->settings ); } if ( 'yes' === $woocommerce_calc_taxes && ! empty( $_POST['woocommerce_import_tax_rates'] ) ) { $locale_info = include( WC()->plugin_path() . '/i18n/locale-info.php' ); $tax_rates = false; if ( isset( $locale_info[ WC()->countries->get_base_country() ] ) ) { if ( isset( $locale_info[ WC()->countries->get_base_country() ]['tax_rates'][ WC()->countries->get_base_state() ] ) ) { $tax_rates = $locale_info[ WC()->countries->get_base_country() ]['tax_rates'][ WC()->countries->get_base_state() ]; } elseif ( isset( $locale_info[ WC()->countries->get_base_country() ]['tax_rates'][''] ) ) { $tax_rates = $locale_info[ WC()->countries->get_base_country() ]['tax_rates']['']; } } if ( $tax_rates ) { $loop = 0; foreach ( $tax_rates as $rate ) { $tax_rate = array( 'tax_rate_country' => $rate['country'], 'tax_rate_state' => $rate['state'], 'tax_rate' => $rate['rate'], 'tax_rate_name' => $rate['name'], 'tax_rate_priority' => 1, 'tax_rate_compound' => 0, 'tax_rate_shipping' => $rate['shipping'] ? 1 : 0, 'tax_rate_order' => $loop ++, 'tax_rate_class' => '' ); $tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate ); } } } wp_redirect( $this->get_next_step_link() ); 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' ); } elseif ( ! empty( $_GET['wc_view_test_product'] ) && isset( $_GET['wc_view_test_product_nonce'] ) && wp_verify_nonce( $_GET['wc_view_test_product_nonce'], 'wc_view_test_product' ) ) { // include & load API classes WC()->api->includes(); WC()->api->register_resources( new WC_API_Server( '/' ) ); $product_id = wc_get_product_id_by_sku( 'test-product' ); if ( empty( $product_id ) ) { $result = WC()->api->WC_API_Products->create_product( array( "product" => array( "title" => "Test Product", "sku" => 'test-product', "type" => "simple", "regular_price" => "21.99", "description" => "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description" => "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories" => array( "Test Category" ) ) ) ); if ( $result && ! is_wp_error( $result ) ) { $product_id = $result['product']['id']; } } if ( $product_id ) { wp_safe_redirect( get_permalink( $product_id ) ); exit; } } } /** * Final step */ public function wc_setup_ready() { $this->wc_setup_ready_actions(); ?> Tweet

', '' ); ?>