WC_Admin_Setup_Wizard

WC_Admin_Setup_Wizard class.

Defined (1)

The class is defined in the following location(s).

/includes/admin/class-wc-admin-setup-wizard.php  
  1. class WC_Admin_Setup_Wizard { 
  2.  
  3. /** @var string Currenct Step */ 
  4. private $step = ''; 
  5.  
  6. /** @var array Steps for the setup wizard */ 
  7. private $steps = array(); 
  8.  
  9. /** @var array Tweets user can optionally send after install */ 
  10. private $tweets = array( 
  11. 'Someone give me woo-t, I just set up a new store with #WordPress and @WooCommerce!',  
  12. 'Someone give me high five, I just set up a new store with #WordPress and @WooCommerce!',  
  13. ); 
  14.  
  15. /** 
  16. * Hook in tabs. 
  17. */ 
  18. public function __construct() { 
  19. if ( apply_filters( 'woocommerce_enable_setup_wizard', true ) && current_user_can( 'manage_woocommerce' ) ) { 
  20. add_action( 'admin_menu', array( $this, 'admin_menus' ) ); 
  21. add_action( 'admin_init', array( $this, 'setup_wizard' ) ); 
  22.  
  23. /** 
  24. * Add admin menus/screens. 
  25. */ 
  26. public function admin_menus() { 
  27. add_dashboard_page( '', '', 'manage_options', 'wc-setup', '' ); 
  28.  
  29. /** 
  30. * Show the setup wizard. 
  31. */ 
  32. public function setup_wizard() { 
  33. if ( empty( $_GET['page'] ) || 'wc-setup' !== $_GET['page'] ) { 
  34. return; 
  35. $default_steps = array( 
  36. 'introduction' => array( 
  37. 'name' => __( 'Introduction', 'woocommerce' ),  
  38. 'view' => array( $this, 'wc_setup_introduction' ),  
  39. 'handler' => '',  
  40. ),  
  41. 'pages' => array( 
  42. 'name' => __( 'Page setup', 'woocommerce' ),  
  43. 'view' => array( $this, 'wc_setup_pages' ),  
  44. 'handler' => array( $this, 'wc_setup_pages_save' ),  
  45. ),  
  46. 'locale' => array( 
  47. 'name' => __( 'Store locale', 'woocommerce' ),  
  48. 'view' => array( $this, 'wc_setup_locale' ),  
  49. 'handler' => array( $this, 'wc_setup_locale_save' ),  
  50. ),  
  51. 'shipping_taxes' => array( 
  52. 'name' => __( 'Shipping & tax', 'woocommerce' ),  
  53. 'view' => array( $this, 'wc_setup_shipping_taxes' ),  
  54. 'handler' => array( $this, 'wc_setup_shipping_taxes_save' ),  
  55. ),  
  56. 'payments' => array( 
  57. 'name' => __( 'Payments', 'woocommerce' ),  
  58. 'view' => array( $this, 'wc_setup_payments' ),  
  59. 'handler' => array( $this, 'wc_setup_payments_save' ),  
  60. ),  
  61. 'next_steps' => array( 
  62. 'name' => __( 'Ready!', 'woocommerce' ),  
  63. 'view' => array( $this, 'wc_setup_ready' ),  
  64. 'handler' => '',  
  65. ),  
  66. ); 
  67.  
  68. $this->steps = apply_filters( 'woocommerce_setup_wizard_steps', $default_steps ); 
  69. $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) ); 
  70. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  71.  
  72. wp_register_script( 'jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true ); 
  73. wp_register_script( 'select2', WC()->plugin_url() . '/assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), '4.0.3' ); 
  74. wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'select2' ), WC_VERSION ); 
  75. wp_localize_script( 'wc-enhanced-select', 'wc_enhanced_select_params', array( 
  76. 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),  
  77. 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),  
  78. 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ),  
  79. 'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ),  
  80. 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ),  
  81. 'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ),  
  82. 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ),  
  83. 'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ),  
  84. 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'woocommerce' ),  
  85. 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'woocommerce' ),  
  86. 'ajax_url' => admin_url( 'admin-ajax.php' ),  
  87. 'search_products_nonce' => wp_create_nonce( 'search-products' ),  
  88. 'search_customers_nonce' => wp_create_nonce( 'search-customers' ),  
  89. ) ); 
  90. wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC_VERSION ); 
  91. wp_enqueue_style( 'wc-setup', WC()->plugin_url() . '/assets/css/wc-setup.css', array( 'dashicons', 'install' ), WC_VERSION ); 
  92.  
  93. wp_register_script( 'wc-setup', WC()->plugin_url() . '/assets/js/admin/wc-setup.min.js', array( 'jquery', 'wc-enhanced-select', 'jquery-blockui' ), WC_VERSION ); 
  94. wp_localize_script( 'wc-setup', 'wc_setup_params', array( 
  95. 'locale_info' => json_encode( include( WC()->plugin_path() . '/i18n/locale-info.php' ) ),  
  96. ) ); 
  97.  
  98. if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) { 
  99. call_user_func( $this->steps[ $this->step ]['handler'], $this ); 
  100.  
  101. ob_start(); 
  102. $this->setup_wizard_header(); 
  103. $this->setup_wizard_steps(); 
  104. $this->setup_wizard_content(); 
  105. $this->setup_wizard_footer(); 
  106. exit; 
  107.  
  108. /** 
  109. * Get the URL for the next step's screen. 
  110. * @param string step slug (default: current step) 
  111. * @return string URL for next step if a next step exists. 
  112. * Admin URL if it's the last step. 
  113. * Empty string on failure. 
  114. * @since 3.0.0 
  115. */ 
  116. public function get_next_step_link( $step = '' ) { 
  117. if ( ! $step ) { 
  118. $step = $this->step; 
  119.  
  120. $keys = array_keys( $this->steps ); 
  121. if ( end( $keys ) === $step ) { 
  122. return admin_url(); 
  123.  
  124. $step_index = array_search( $step, $keys ); 
  125. if ( false === $step_index ) { 
  126. return ''; 
  127.  
  128. return add_query_arg( 'step', $keys[ $step_index + 1 ] ); 
  129.  
  130. /** 
  131. * Setup Wizard Header. 
  132. */ 
  133. public function setup_wizard_header() { 
  134. ?> 
  135. <!DOCTYPE html> 
  136. <html <?php language_attributes(); ?>> 
  137. <head> 
  138. <meta name="viewport" content="width=device-width" /> 
  139. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  140. <title><?php esc_html_e( 'WooCommerce › Setup Wizard', 'woocommerce' ); ?></title> 
  141. <?php wp_print_scripts( 'wc-setup' ); ?> 
  142. <?php do_action( 'admin_print_styles' ); ?> 
  143. <?php do_action( 'admin_head' ); ?> 
  144. </head> 
  145. <body class="wc-setup wp-core-ui"> 
  146. <h1 id="wc-logo"><a href="https://woocommerce.com/"><img src="<?php echo WC()->plugin_url(); ?>/assets/images/woocommerce_logo.png" alt="WooCommerce" /></a></h1> 
  147. <?php 
  148.  
  149. /** 
  150. * Setup Wizard Footer. 
  151. */ 
  152. public function setup_wizard_footer() { 
  153. ?> 
  154. <?php if ( 'next_steps' === $this->step ) : ?> 
  155. <a class="wc-return-to-dashboard" href="<?php echo esc_url( admin_url() ); ?>"><?php esc_html_e( 'Return to the WordPress Dashboard', 'woocommerce' ); ?></a> 
  156. <?php endif; ?> 
  157. </body> 
  158. </html> 
  159. <?php 
  160.  
  161. /** 
  162. * Output the steps. 
  163. */ 
  164. public function setup_wizard_steps() { 
  165. $ouput_steps = $this->steps; 
  166. array_shift( $ouput_steps ); 
  167. ?> 
  168. <ol class="wc-setup-steps"> 
  169. <?php foreach ( $ouput_steps as $step_key => $step ) : ?> 
  170. <li class="<?php 
  171. if ( $step_key === $this->step ) { 
  172. echo 'active'; 
  173. } elseif ( array_search( $this->step, array_keys( $this->steps ) ) > array_search( $step_key, array_keys( $this->steps ) ) ) { 
  174. echo 'done'; 
  175. ?>"><?php echo esc_html( $step['name'] ); ?></li> 
  176. <?php endforeach; ?> 
  177. </ol> 
  178. <?php 
  179.  
  180. /** 
  181. * Output the content for the current step. 
  182. */ 
  183. public function setup_wizard_content() { 
  184. echo '<div class="wc-setup-content">'; 
  185. call_user_func( $this->steps[ $this->step ]['view'], $this ); 
  186. echo '</div>'; 
  187.  
  188. /** 
  189. * Introduction step. 
  190. */ 
  191. public function wc_setup_introduction() { 
  192. ?> 
  193. <h1><?php esc_html_e( 'Welcome to the world of WooCommerce!', 'woocommerce' ); ?></h1> 
  194. <p><?php _e( 'Thank you for choosing WooCommerce to power your online store! This quick setup wizard will help you configure the basic settings. <strong>It*s completely optional and shouldn*t take longer than five minutes.</strong>', 'woocommerce' ); ?></p> 
  195. <p><?php esc_html_e( 'No time right now? If you don*t want to go through the wizard, you can skip and return to the WordPress dashboard. Come back anytime if you change your mind!', 'woocommerce' ); ?></p> 
  196. <p class="wc-setup-actions step"> 
  197. <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" class="button-primary button button-large button-next"><?php esc_html_e( 'Let\'s go!', 'woocommerce' ); ?></a> 
  198. <a href="<?php echo esc_url( admin_url() ); ?>" class="button button-large"><?php esc_html_e( 'Not right now', 'woocommerce' ); ?></a> 
  199. </p> 
  200. <?php 
  201.  
  202. /** 
  203. * Page setup. 
  204. */ 
  205. public function wc_setup_pages() { 
  206. ?> 
  207. <h1><?php esc_html_e( 'Page setup', 'woocommerce' ); ?></h1> 
  208. <form method="post"> 
  209. <p><?php printf( __( 'Your store needs a few essential <a href="%s" target="_blank">pages</a>. The following will be created automatically (if they do not already exist):', 'woocommerce' ), esc_url( admin_url( 'edit.php?post_type=page' ) ) ); ?></p> 
  210. <table class="wc-setup-pages" cellspacing="0"> 
  211. <thead> 
  212. <tr> 
  213. <th class="page-name"><?php esc_html_e( 'Page name', 'woocommerce' ); ?></th> 
  214. <th class="page-description"><?php esc_html_e( 'Description', 'woocommerce' ); ?></th> 
  215. </tr> 
  216. </thead> 
  217. <tbody> 
  218. <tr> 
  219. <td class="page-name"><?php echo _x( 'Shop', 'Page title', 'woocommerce' ); ?></td> 
  220. <td><?php esc_html_e( 'The shop page will display your products.', 'woocommerce' ); ?></td> 
  221. </tr> 
  222. <tr> 
  223. <td class="page-name"><?php echo _x( 'Cart', 'Page title', 'woocommerce' ); ?></td> 
  224. <td><?php esc_html_e( 'The cart page will be where the customers go to view their cart and begin checkout.', 'woocommerce' ); ?></td> 
  225. </tr> 
  226. <tr> 
  227. <td class="page-name"><?php echo _x( 'Checkout', 'Page title', 'woocommerce' ); ?></td> 
  228. <td> 
  229. <?php esc_html_e( 'The checkout page will be where the customers go to pay for their items.', 'woocommerce' ); ?> 
  230. </td> 
  231. </tr> 
  232. <tr> 
  233. <td class="page-name"><?php echo _x( 'My account', 'Page title', 'woocommerce' ); ?></td> 
  234. <td> 
  235. <?php esc_html_e( 'Registered customers will be able to manage their account details and view past orders on this page.', 'woocommerce' ); ?> 
  236. </td> 
  237. </tr> 
  238. </tbody> 
  239. </table> 
  240.  
  241. <p><?php printf( __( 'Once created, these pages can be managed from your admin dashboard on the <a href="%1$s" target="_blank">Pages screen</a>. You can control which pages are shown on your website via <a href="%2$s" target="_blank">Appearance > Menus</a>.', 'woocommerce' ), esc_url( admin_url( 'edit.php?post_type=page' ) ), esc_url( admin_url( 'nav-menus.php' ) ) ); ?></p> 
  242.  
  243. <p class="wc-setup-actions step"> 
  244. <input type="submit" class="button-primary button button-large button-next" value="<?php esc_attr_e( 'Continue', 'woocommerce' ); ?>" name="save_step" /> 
  245. <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" class="button button-large button-next"><?php esc_html_e( 'Skip this step', 'woocommerce' ); ?></a> 
  246. <?php wp_nonce_field( 'wc-setup' ); ?> 
  247. </p> 
  248. </form> 
  249. <?php 
  250.  
  251. /** 
  252. * Save Page Settings. 
  253. */ 
  254. public function wc_setup_pages_save() { 
  255. check_admin_referer( 'wc-setup' ); 
  256.  
  257. WC_Install::create_pages(); 
  258. wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); 
  259. exit; 
  260.  
  261. /** 
  262. * Locale settings. 
  263. */ 
  264. public function wc_setup_locale() { 
  265. $user_location = WC_Geolocation::geolocate_ip(); 
  266. $country = ! empty( $user_location['country'] ) ? $user_location['country'] : 'US'; 
  267. $state = ! empty( $user_location['state'] ) ? $user_location['state'] : '*'; 
  268. $state = 'US' === $country && '*' === $state ? 'AL' : $state; 
  269.  
  270. // Defaults 
  271. $currency = get_option( 'woocommerce_currency', 'GBP' ); 
  272. $currency_pos = get_option( 'woocommerce_currency_pos', 'left' ); 
  273. $decimal_sep = get_option( 'woocommerce_price_decimal_sep', '.' ); 
  274. $num_decimals = get_option( 'woocommerce_price_num_decimals', '2' ); 
  275. $thousand_sep = get_option( 'woocommerce_price_thousand_sep', ', ' ); 
  276. $dimension_unit = get_option( 'woocommerce_dimension_unit', 'cm' ); 
  277. $weight_unit = get_option( 'woocommerce_weight_unit', 'kg' ); 
  278. ?> 
  279. <h1><?php esc_html_e( 'Store locale setup', 'woocommerce' ); ?></h1> 
  280. <form method="post"> 
  281. <table class="form-table"> 
  282. <tr> 
  283. <th scope="row"><label for="store_location"><?php esc_html_e( 'Where is your store based?', 'woocommerce' ); ?></label></th> 
  284. <td> 
  285. <select id="store_location" name="store_location" style="width:100%;" required data-placeholder="<?php esc_attr_e( 'Choose a country…', 'woocommerce' ); ?>" class="wc-enhanced-select"> 
  286. <?php WC()->countries->country_dropdown_options( $country, $state ); ?> 
  287. </select> 
  288. </td> 
  289. </tr> 
  290. <tr> 
  291. <th scope="row"><label for="currency_code"><?php esc_html_e( 'Which currency will your store use?', 'woocommerce' ); ?></label></th> 
  292. <td> 
  293. <select id="currency_code" name="currency_code" style="width:100%;" data-placeholder="<?php esc_attr_e( 'Choose a currency…', 'woocommerce' ); ?>" class="wc-enhanced-select"> 
  294. <option value=""><?php esc_html_e( 'Choose a currency…', 'woocommerce' ); ?></option> 
  295. <?php 
  296. foreach ( get_woocommerce_currencies() as $code => $name ) { 
  297. echo '<option value="' . esc_attr( $code ) . '" ' . selected( $currency, $code, false ) . '>' . sprintf( esc_html__( '%1$s (%2$s)', 'woocommerce' ), $name, get_woocommerce_currency_symbol( $code ) ) . '</option>'; 
  298. ?> 
  299. </select> 
  300. <span class="description"><?php printf( __( 'If your currency is not listed you can <a href="%s" target="_blank">add it later</a>.', 'woocommerce' ), 'https://docs.woocommerce.com/document/add-a-custom-currency-symbol/' ); ?></span> 
  301. </td> 
  302. </tr> 
  303. <tr> 
  304. <th scope="row"><label for="currency_pos"><?php esc_html_e( 'Currency position', 'woocommerce' ); ?></label></th> 
  305. <td> 
  306. <select id="currency_pos" name="currency_pos" class="wc-enhanced-select"> 
  307. <option value="left" <?php selected( $currency_pos, 'left' ); ?>><?php esc_html_e( 'Left', 'woocommerce' ); ?></option> 
  308. <option value="right" <?php selected( $currency_pos, 'right' ); ?>><?php esc_html_e( 'Right', 'woocommerce' ); ?></option> 
  309. <option value="left_space" <?php selected( $currency_pos, 'left_space' ); ?>><?php esc_html_e( 'Left with space', 'woocommerce' ); ?></option> 
  310. <option value="right_space" <?php selected( $currency_pos, 'right_space' ); ?>><?php esc_html_e( 'Right with space', 'woocommerce' ); ?></option> 
  311. </select> 
  312. </td> 
  313. </tr> 
  314. <tr> 
  315. <th scope="row"><label for="thousand_sep"><?php esc_html_e( 'Thousand separator', 'woocommerce' ); ?></label></th> 
  316. <td> 
  317. <input type="text" id="thousand_sep" name="thousand_sep" size="2" value="<?php echo esc_attr( $thousand_sep ); ?>" /> 
  318. </td> 
  319. </tr> 
  320. <tr> 
  321. <th scope="row"><label for="decimal_sep"><?php esc_html_e( 'Decimal separator', 'woocommerce' ); ?></label></th> 
  322. <td> 
  323. <input type="text" id="decimal_sep" name="decimal_sep" size="2" value="<?php echo esc_attr( $decimal_sep ); ?>" /> 
  324. </td> 
  325. </tr> 
  326. <tr> 
  327. <th scope="row"><label for="num_decimals"><?php esc_html_e( 'Number of decimals', 'woocommerce' ); ?></label></th> 
  328. <td> 
  329. <input type="text" id="num_decimals" name="num_decimals" size="2" value="<?php echo esc_attr( $num_decimals ); ?>" /> 
  330. </td> 
  331. </tr> 
  332. <tr> 
  333. <th scope="row"><label for="weight_unit"><?php esc_html_e( 'Which unit should be used for product weights?', 'woocommerce' ); ?></label></th> 
  334. <td> 
  335. <select id="weight_unit" name="weight_unit" class="wc-enhanced-select"> 
  336. <option value="kg" <?php selected( $weight_unit, 'kg' ); ?>><?php esc_html_e( 'kg', 'woocommerce' ); ?></option> 
  337. <option value="g" <?php selected( $weight_unit, 'g' ); ?>><?php esc_html_e( 'g', 'woocommerce' ); ?></option> 
  338. <option value="lbs" <?php selected( $weight_unit, 'lbs' ); ?>><?php esc_html_e( 'lbs', 'woocommerce' ); ?></option> 
  339. <option value="oz" <?php selected( $weight_unit, 'oz' ); ?>><?php esc_html_e( 'oz', 'woocommerce' ); ?></option> 
  340. </select> 
  341. </td> 
  342. </tr> 
  343. <tr> 
  344. <th scope="row"><label for="dimension_unit"><?php esc_html_e( 'Which unit should be used for product dimensions?', 'woocommerce' ); ?></label></th> 
  345. <td> 
  346. <select id="dimension_unit" name="dimension_unit" class="wc-enhanced-select"> 
  347. <option value="m" <?php selected( $dimension_unit, 'm' ); ?>><?php esc_html_e( 'm', 'woocommerce' ); ?></option> 
  348. <option value="cm" <?php selected( $dimension_unit, 'cm' ); ?>><?php esc_html_e( 'cm', 'woocommerce' ); ?></option> 
  349. <option value="mm" <?php selected( $dimension_unit, 'mm' ); ?>><?php esc_html_e( 'mm', 'woocommerce' ); ?></option> 
  350. <option value="in" <?php selected( $dimension_unit, 'in' ); ?>><?php esc_html_e( 'in', 'woocommerce' ); ?></option> 
  351. <option value="yd" <?php selected( $dimension_unit, 'yd' ); ?>><?php esc_html_e( 'yd', 'woocommerce' ); ?></option> 
  352. </select> 
  353. </td> 
  354. </tr> 
  355. </table> 
  356. <p class="wc-setup-actions step"> 
  357. <input type="submit" class="button-primary button button-large button-next" value="<?php esc_attr_e( 'Continue', 'woocommerce' ); ?>" name="save_step" /> 
  358. <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" class="button button-large button-next"><?php esc_html_e( 'Skip this step', 'woocommerce' ); ?></a> 
  359. <?php wp_nonce_field( 'wc-setup' ); ?> 
  360. </p> 
  361. </form> 
  362. <?php 
  363.  
  364. /** 
  365. * Save Locale Settings. 
  366. */ 
  367. public function wc_setup_locale_save() { 
  368. check_admin_referer( 'wc-setup' ); 
  369.  
  370. $store_location = sanitize_text_field( $_POST['store_location'] ); 
  371. $currency_code = sanitize_text_field( $_POST['currency_code'] ); 
  372. $currency_pos = sanitize_text_field( $_POST['currency_pos'] ); 
  373. $decimal_sep = sanitize_text_field( $_POST['decimal_sep'] ); 
  374. $num_decimals = sanitize_text_field( $_POST['num_decimals'] ); 
  375. $thousand_sep = sanitize_text_field( $_POST['thousand_sep'] ); 
  376. $weight_unit = sanitize_text_field( $_POST['weight_unit'] ); 
  377. $dimension_unit = sanitize_text_field( $_POST['dimension_unit'] ); 
  378.  
  379. update_option( 'woocommerce_default_country', $store_location ); 
  380. update_option( 'woocommerce_currency', $currency_code ); 
  381. update_option( 'woocommerce_currency_pos', $currency_pos ); 
  382. update_option( 'woocommerce_price_decimal_sep', $decimal_sep ); 
  383. update_option( 'woocommerce_price_num_decimals', $num_decimals ); 
  384. update_option( 'woocommerce_price_thousand_sep', $thousand_sep ); 
  385. update_option( 'woocommerce_weight_unit', $weight_unit ); 
  386. update_option( 'woocommerce_dimension_unit', $dimension_unit ); 
  387.  
  388. wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); 
  389. exit; 
  390.  
  391. /** 
  392. * Shipping and taxes. 
  393. */ 
  394. public function wc_setup_shipping_taxes() { 
  395. ?> 
  396. <h1><?php esc_html_e( 'Shipping & Tax setup', 'woocommerce' ); ?></h1> 
  397. <form method="post"> 
  398. <p><?php esc_html_e( 'If you will be charging sales tax, or shipping physical goods to customers, you can enable these below. This is optional and can be changed later.', 'woocommerce' ); ?></p> 
  399. <table class="form-table"> 
  400. <tr> 
  401. <th scope="row"><label for="woocommerce_calc_shipping"><?php esc_html_e( 'Will you be shipping products?', 'woocommerce' ); ?></label></th> 
  402. <td> 
  403. <input type="checkbox" id="woocommerce_calc_shipping" <?php checked( get_option( 'woocommerce_ship_to_countries', '' ) !== 'disabled', true ); ?> name="woocommerce_calc_shipping" class="input-checkbox" value="1" /> 
  404. <label for="woocommerce_calc_shipping"><?php esc_html_e( 'Yes, I will be shipping physical goods to customers', 'woocommerce' ); ?></label> 
  405. </td> 
  406. </tr> 
  407. <tr> 
  408. <th scope="row"><label for="woocommerce_calc_taxes"><?php esc_html_e( 'Will you be charging sales tax?', 'woocommerce' ); ?></label></th> 
  409. <td> 
  410. <input type="checkbox" <?php checked( get_option( 'woocommerce_calc_taxes', 'no' ), 'yes' ); ?> id="woocommerce_calc_taxes" name="woocommerce_calc_taxes" class="input-checkbox" value="1" /> 
  411. <label for="woocommerce_calc_taxes"><?php esc_html_e( 'Yes, I will be charging sales tax', 'woocommerce' ); ?></label> 
  412. </td> 
  413. </tr> 
  414. <tr> 
  415. <th scope="row"><label for="woocommerce_prices_include_tax"><?php esc_html_e( 'How will you enter product prices?', 'woocommerce' ); ?></label></th> 
  416. <td> 
  417. <label><input type="radio" <?php checked( get_option( 'woocommerce_prices_include_tax', 'no' ), 'yes' ); ?> id="woocommerce_prices_include_tax" name="woocommerce_prices_include_tax" class="input-radio" value="yes" /> <?php esc_html_e( 'I will enter prices inclusive of tax', 'woocommerce' ); ?></label><br/> 
  418. <label><input type="radio" <?php checked( get_option( 'woocommerce_prices_include_tax', 'no' ), 'no' ); ?> id="woocommerce_prices_include_tax" name="woocommerce_prices_include_tax" class="input-radio" value="no" /> <?php esc_html_e( 'I will enter prices exclusive of tax', 'woocommerce' ); ?></label> 
  419. </td> 
  420. </tr> 
  421. <?php 
  422. $locale_info = include( WC()->plugin_path() . '/i18n/locale-info.php' ); 
  423. $tax_rates = array(); 
  424. $country = WC()->countries->get_base_country(); 
  425. $state = WC()->countries->get_base_state(); 
  426.  
  427. if ( isset( $locale_info[ $country ] ) ) { 
  428. if ( isset( $locale_info[ $country ]['tax_rates'][ $state ] ) ) { 
  429. $tax_rates = $locale_info[ $country ]['tax_rates'][ $state ]; 
  430. } elseif ( isset( $locale_info[ $country ]['tax_rates'][''] ) ) { 
  431. $tax_rates = $locale_info[ $country ]['tax_rates']['']; 
  432. if ( isset( $locale_info[ $country ]['tax_rates']['*'] ) ) { 
  433. $tax_rates = array_merge( $locale_info[ $country ]['tax_rates']['*'], $tax_rates ); 
  434. if ( $tax_rates ) { 
  435. ?> 
  436. <tr class="tax-rates"> 
  437. <td colspan="2"> 
  438. <p><?php printf( __( 'The following tax rates will be imported automatically for you. You can read more about taxes in <a href="%s" target="_blank">our documentation</a>.', 'woocommerce' ), 'https://docs.woocommerce.com/document/setting-up-taxes-in-woocommerce/' ); ?></p> 
  439. <div class="importing-tax-rates"> 
  440. <table class="tax-rates"> 
  441. <thead> 
  442. <tr> 
  443. <th><?php esc_html_e( 'Country', 'woocommerce' ); ?></th> 
  444. <th><?php esc_html_e( 'State', 'woocommerce' ); ?></th> 
  445. <th><?php esc_html_e( 'Rate (%)', 'woocommerce' ); ?></th> 
  446. <th><?php esc_html_e( 'Name', 'woocommerce' ); ?></th> 
  447. </tr> 
  448. </thead> 
  449. <tbody> 
  450. <?php 
  451. foreach ( $tax_rates as $rate ) { 
  452. ?> 
  453. <tr> 
  454. <td class="readonly"><?php echo esc_attr( $rate['country'] ); ?></td> 
  455. <td class="readonly"><?php echo esc_attr( $rate['state'] ? $rate['state'] : '*' ); ?></td> 
  456. <td class="readonly"><?php echo esc_attr( $rate['rate'] ); ?></td> 
  457. <td class="readonly"><?php echo esc_attr( $rate['name'] ); ?></td> 
  458. </tr> 
  459. <?php 
  460. ?> 
  461. </tbody> 
  462. </table> 
  463. </div> 
  464. <p class="description"><?php printf( __( 'You may need to add/edit rates based on your products or business location which can be done from the <a href="%s" target="_blank">tax settings</a> screen. If in doubt, speak to an accountant.', 'woocommerce' ), esc_url( admin_url( 'admin.php?page=wc-settings&tab=tax' ) ) ); ?></p> 
  465. </td> 
  466. </tr> 
  467. <?php 
  468. ?> 
  469. </table> 
  470. <p class="wc-setup-actions step"> 
  471. <input type="submit" class="button-primary button button-large button-next" value="<?php esc_attr_e( 'Continue', 'woocommerce' ); ?>" name="save_step" /> 
  472. <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" class="button button-large button-next"><?php esc_html_e( 'Skip this step', 'woocommerce' ); ?></a> 
  473. <?php wp_nonce_field( 'wc-setup' ); ?> 
  474. </p> 
  475. </form> 
  476. <?php 
  477.  
  478. /** 
  479. * Save shipping and tax options. 
  480. */ 
  481. public function wc_setup_shipping_taxes_save() { 
  482. check_admin_referer( 'wc-setup' ); 
  483.  
  484. $enable_shipping = isset( $_POST['woocommerce_calc_shipping'] ); 
  485. $enable_taxes = isset( $_POST['woocommerce_calc_taxes'] ); 
  486.  
  487. if ( $enable_shipping ) { 
  488. update_option( 'woocommerce_ship_to_countries', '' ); 
  489. WC_Admin_Notices::add_notice( 'no_shipping_methods' ); 
  490. } else { 
  491. update_option( 'woocommerce_ship_to_countries', 'disabled' ); 
  492.  
  493. update_option( 'woocommerce_calc_taxes', $enable_taxes ? 'yes' : 'no' ); 
  494. update_option( 'woocommerce_prices_include_tax', sanitize_text_field( $_POST['woocommerce_prices_include_tax'] ) ); 
  495.  
  496. if ( $enable_taxes ) { 
  497. $locale_info = include( WC()->plugin_path() . '/i18n/locale-info.php' ); 
  498. $tax_rates = array(); 
  499. $country = WC()->countries->get_base_country(); 
  500. $state = WC()->countries->get_base_state(); 
  501.  
  502. if ( isset( $locale_info[ $country ] ) ) { 
  503. if ( isset( $locale_info[ $country ]['tax_rates'][ $state ] ) ) { 
  504. $tax_rates = $locale_info[ $country ]['tax_rates'][ $state ]; 
  505. } elseif ( isset( $locale_info[ $country ]['tax_rates'][''] ) ) { 
  506. $tax_rates = $locale_info[ $country ]['tax_rates']['']; 
  507. if ( isset( $locale_info[ $country ]['tax_rates']['*'] ) ) { 
  508. $tax_rates = array_merge( $locale_info[ $country ]['tax_rates']['*'], $tax_rates ); 
  509. if ( $tax_rates ) { 
  510. $loop = 0; 
  511. foreach ( $tax_rates as $rate ) { 
  512. $tax_rate = array( 
  513. 'tax_rate_country' => $rate['country'],  
  514. 'tax_rate_state' => $rate['state'],  
  515. 'tax_rate' => $rate['rate'],  
  516. 'tax_rate_name' => $rate['name'],  
  517. 'tax_rate_priority' => isset( $rate['priority'] ) ? absint( $rate['priority'] ) : 1,  
  518. 'tax_rate_compound' => 0,  
  519. 'tax_rate_shipping' => $rate['shipping'] ? 1 : 0,  
  520. 'tax_rate_order' => $loop ++,  
  521. 'tax_rate_class' => '',  
  522. ); 
  523. WC_Tax::_insert_tax_rate( $tax_rate ); 
  524.  
  525. wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); 
  526. exit; 
  527.  
  528. /** 
  529. * Simple array of gateways to show in wizard. 
  530. * @return array 
  531. */ 
  532. protected function get_wizard_payment_gateways() { 
  533. $gateways = array( 
  534. 'paypal-braintree' => array( 
  535. 'name' => __( 'PayPal by Braintree', 'woocommerce' ),  
  536. 'image' => WC()->plugin_url() . '/assets/images/paypal-braintree.png',  
  537. 'description' => sprintf( __( 'Safe and secure payments using credit cards or your customer\'s PayPal account. <a href="%s" target="_blank">Learn more about PayPal</a>.', 'woocommerce' ), 'https://wordpress.org/plugins/woocommerce-gateway-paypal-powered-by-braintree/' ),  
  538. 'class' => 'featured featured-row-last',  
  539. 'repo-slug' => 'woocommerce-gateway-paypal-powered-by-braintree',  
  540. ),  
  541. 'paypal-ec' => array( 
  542. 'name' => __( 'PayPal Express Checkout', 'woocommerce' ),  
  543. 'image' => WC()->plugin_url() . '/assets/images/paypal.png',  
  544. 'description' => sprintf( __( 'Safe and secure payments using credit cards or your customer\'s PayPal account. <a href="%s" target="_blank">Learn more about PayPal</a>.', 'woocommerce' ), 'https://wordpress.org/plugins/woocommerce-gateway-paypal-express-checkout/' ),  
  545. 'class' => 'featured featured-row-last',  
  546. 'repo-slug' => 'woocommerce-gateway-paypal-express-checkout',  
  547. ),  
  548. 'stripe' => array( 
  549. 'name' => __( 'Stripe', 'woocommerce' ),  
  550. 'image' => WC()->plugin_url() . '/assets/images/stripe.png',  
  551. 'description' => sprintf( __( 'A modern and robust way to accept credit card payments on your store. <a href="%s" target="_blank">Learn more about Stripe</a>.', 'woocommerce' ), 'https://wordpress.org/plugins/woocommerce-gateway-stripe/' ),  
  552. 'class' => 'featured featured-row-first',  
  553. 'repo-slug' => 'woocommerce-gateway-stripe',  
  554. ),  
  555. 'paypal' => array( 
  556. 'name' => __( 'PayPal Standard', 'woocommerce' ),  
  557. 'description' => __( 'Accept payments via PayPal using account balance or credit card.', 'woocommerce' ),  
  558. 'image' => '',  
  559. 'class' => '',  
  560. 'settings' => array( 
  561. 'email' => array( 
  562. 'label' => __( 'PayPal email address', 'woocommerce' ),  
  563. 'type' => 'email',  
  564. 'value' => get_option( 'admin_email' ),  
  565. 'placeholder' => __( 'PayPal email address', 'woocommerce' ),  
  566. ),  
  567. ),  
  568. ),  
  569. 'cheque' => array( 
  570. 'name' => _x( 'Check payments', 'Check payment method', 'woocommerce' ),  
  571. 'description' => __( 'A simple offline gateway that lets you accept a check as method of payment.', 'woocommerce' ),  
  572. 'image' => '',  
  573. 'class' => '',  
  574. ),  
  575. 'bacs' => array( 
  576. 'name' => __( 'Bank transfer (BACS) payments', 'woocommerce' ),  
  577. 'description' => __( 'A simple offline gateway that lets you accept BACS payment.', 'woocommerce' ),  
  578. 'image' => '',  
  579. 'class' => '',  
  580. ),  
  581. 'cod' => array( 
  582. 'name' => __( 'Cash on delivery', 'woocommerce' ),  
  583. 'description' => __( 'A simple offline gateway that lets you accept cash on delivery.', 'woocommerce' ),  
  584. 'image' => '',  
  585. 'class' => '',  
  586. ),  
  587. ); 
  588.  
  589. $country = WC()->countries->get_base_country(); 
  590.  
  591. if ( 'US' === $country ) { 
  592. unset( $gateways['paypal-ec'] ); 
  593. } else { 
  594. unset( $gateways['paypal-braintree'] ); 
  595.  
  596. if ( ! current_user_can( 'install_plugins' ) ) { 
  597. unset( $gateways['paypal-braintree'] ); 
  598. unset( $gateways['paypal-ec'] ); 
  599. unset( $gateways['stripe'] ); 
  600.  
  601. return $gateways; 
  602.  
  603. /** 
  604. * Payments Step. 
  605. */ 
  606. public function wc_setup_payments() { 
  607. $gateways = $this->get_wizard_payment_gateways(); 
  608. ?> 
  609. <h1><?php esc_html_e( 'Payments', 'woocommerce' ); ?></h1> 
  610. <form method="post" class="wc-wizard-payment-gateway-form"> 
  611. <p><?php printf( __( 'WooCommerce can accept both online and offline payments. <a href="%1$s" target="_blank">Additional payment methods</a> can be installed later and managed from the <a href="%2$s" target="_blank">checkout settings</a> screen.', 'woocommerce' ), esc_url( admin_url( 'admin.php?page=wc-addons&view=payment-gateways' ) ), esc_url( admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) ); ?></p> 
  612.  
  613. <ul class="wc-wizard-payment-gateways"> 
  614. <?php foreach ( $gateways as $gateway_id => $gateway ) : ?> 
  615. <li class="wc-wizard-gateway wc-wizard-gateway-<?php echo esc_attr( $gateway_id ); ?> <?php echo esc_attr( $gateway['class'] ); ?>"> 
  616. <div class="wc-wizard-gateway-enable"> 
  617. <input type="checkbox" name="wc-wizard-gateway-<?php echo esc_attr( $gateway_id ); ?>-enabled" class="input-checkbox" value="yes" /> 
  618. <label> 
  619. <?php if ( $gateway['image'] ) : ?> 
  620. <img src="<?php echo esc_attr( $gateway['image'] ); ?>" alt="<?php echo esc_attr( $gateway['name'] ); ?>" /> 
  621. <?php else : ?> 
  622. <?php echo esc_html( $gateway['name'] ); ?> 
  623. <?php endif; ?> 
  624. </label> 
  625. </div> 
  626. <div class="wc-wizard-gateway-description"> 
  627. <?php echo wp_kses_post( wpautop( $gateway['description'] ) ); ?> 
  628. </div> 
  629. <?php if ( ! empty( $gateway['settings'] ) ) : ?> 
  630. <table class="form-table wc-wizard-gateway-settings"> 
  631. <?php foreach ( $gateway['settings'] as $setting_id => $setting ) : ?> 
  632. <tr> 
  633. <th scope="row"><label for="<?php echo esc_attr( $gateway_id ); ?>_<?php echo esc_attr( $setting_id ); ?>"><?php echo esc_html( $setting['label'] ); ?>:</label></th> 
  634. <td> 
  635. <input 
  636. type="<?php echo esc_attr( $setting['type'] ); ?>" 
  637. id="<?php echo esc_attr( $gateway_id ); ?>_<?php echo esc_attr( $setting_id ); ?>" 
  638. name="<?php echo esc_attr( $gateway_id ); ?>_<?php echo esc_attr( $setting_id ); ?>" 
  639. class="input-text" 
  640. value="<?php echo esc_attr( $setting['value'] ); ?>" 
  641. placeholder="<?php echo esc_attr( $setting['placeholder'] ); ?>" 
  642. /> 
  643. </td> 
  644. </tr> 
  645. <?php endforeach; ?> 
  646. </table> 
  647. <?php endif; ?> 
  648. </li> 
  649. <?php endforeach; ?> 
  650. </ul> 
  651. <p class="wc-setup-actions step"> 
  652. <input type="submit" class="button-primary button button-large button-next" value="<?php esc_attr_e( 'Continue', 'woocommerce' ); ?>" name="save_step" /> 
  653. <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" class="button button-large button-next"><?php esc_html_e( 'Skip this step', 'woocommerce' ); ?></a> 
  654. <?php wp_nonce_field( 'wc-setup' ); ?> 
  655. </p> 
  656. </form> 
  657. <?php 
  658.  
  659. /** 
  660. * Payments Step save. 
  661. */ 
  662. public function wc_setup_payments_save() { 
  663. check_admin_referer( 'wc-setup' ); 
  664.  
  665. $gateways = $this->get_wizard_payment_gateways(); 
  666.  
  667. foreach ( $gateways as $gateway_id => $gateway ) { 
  668. // If repo-slug is defined, download and install plugin from .org. 
  669. if ( ! empty( $gateway['repo-slug'] ) && ! empty( $_POST[ 'wc-wizard-gateway-' . $gateway_id . '-enabled' ] ) ) { 
  670. wp_schedule_single_event( time() + 10, 'woocommerce_plugin_background_installer', array( $gateway_id, $gateway ) ); 
  671.  
  672. $settings_key = 'woocommerce_' . $gateway_id . '_settings'; 
  673. $settings = array_filter( (array) get_option( $settings_key, array() ) ); 
  674. $settings['enabled'] = ! empty( $_POST[ 'wc-wizard-gateway-' . $gateway_id . '-enabled' ] ) ? 'yes' : 'no'; 
  675.  
  676. if ( ! empty( $gateway['settings'] ) ) { 
  677. foreach ( $gateway['settings'] as $setting_id => $setting ) { 
  678. $settings[ $setting_id ] = wc_clean( $_POST[ $gateway_id . '_' . $setting_id ] ); 
  679.  
  680. update_option( $settings_key, $settings ); 
  681.  
  682. wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); 
  683. exit; 
  684.  
  685. /** 
  686. * Actions on the final step. 
  687. */ 
  688. private function wc_setup_ready_actions() { 
  689. WC_Admin_Notices::remove_notice( 'install' ); 
  690.  
  691. if ( isset( $_GET['wc_tracker_optin'] ) && isset( $_GET['wc_tracker_nonce'] ) && wp_verify_nonce( $_GET['wc_tracker_nonce'], 'wc_tracker_optin' ) ) { 
  692. update_option( 'woocommerce_allow_tracking', 'yes' ); 
  693. WC_Tracker::send_tracking_data( true ); 
  694.  
  695. } elseif ( isset( $_GET['wc_tracker_optout'] ) && isset( $_GET['wc_tracker_nonce'] ) && wp_verify_nonce( $_GET['wc_tracker_nonce'], 'wc_tracker_optout' ) ) { 
  696. update_option( 'woocommerce_allow_tracking', 'no' ); 
  697.  
  698. /** 
  699. * Final step. 
  700. */ 
  701. public function wc_setup_ready() { 
  702. $this->wc_setup_ready_actions(); 
  703. shuffle( $this->tweets ); 
  704. ?> 
  705. <a href="https://twitter.com/share" class="twitter-share-button" data-url="https://woocommerce.com/" data-text="<?php echo esc_attr( $this->tweets[0] ); ?>" data-via="WooCommerce" data-size="large">Tweet</a> 
  706. <script>!function(d, s, id) {var js, fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)) {js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js, fjs);}}(document, "script", "twitter-wjs");</script> 
  707.  
  708. <h1><?php esc_html_e( 'Your store is ready!', 'woocommerce' ); ?></h1> 
  709.  
  710. <?php if ( 'unknown' === get_option( 'woocommerce_allow_tracking', 'unknown' ) ) : ?> 
  711. <div class="woocommerce-message woocommerce-tracker"> 
  712. <p><?php printf( __( 'Want to help make WooCommerce even more awesome? Allow WooCommerce to collect non-sensitive diagnostic data and usage information. %1$sFind out more%2$s.', 'woocommerce' ), '<a href="https://woocommerce.com/usage-tracking/" target="_blank">', '</a>' ); ?></p> 
  713. <p class="submit"> 
  714. <a class="button-primary button button-large" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc_tracker_optin', 'true' ), 'wc_tracker_optin', 'wc_tracker_nonce' ) ); ?>"><?php esc_html_e( 'Allow', 'woocommerce' ); ?></a> 
  715. <a class="button-secondary button button-large skip" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc_tracker_optout', 'true' ), 'wc_tracker_optout', 'wc_tracker_nonce' ) ); ?>"><?php esc_html_e( 'No thanks', 'woocommerce' ); ?></a> 
  716. </p> 
  717. </div> 
  718. <?php endif; ?> 
  719.  
  720. <div class="wc-setup-next-steps"> 
  721. <div class="wc-setup-next-steps-first"> 
  722. <h2><?php esc_html_e( 'Next steps', 'woocommerce' ); ?></h2> 
  723. <ul> 
  724. <li class="setup-product"><a class="button button-primary button-large" href="<?php echo esc_url( admin_url( 'post-new.php?post_type=product&tutorial=true' ) ); ?>"><?php esc_html_e( 'Create your first product!', 'woocommerce' ); ?></a></li> 
  725. </ul> 
  726. </div> 
  727. <div class="wc-setup-next-steps-last"> 
  728. <h2><?php _e( 'Learn more', 'woocommerce' ); ?></h2> 
  729. <ul> 
  730. <li class="video-walkthrough"><a href="https://docs.woocommerce.com/document/woocommerce-guided-tour-videos/?utm_source=setupwizard&utm_medium=product&utm_content=videos&utm_campaign=woocommerceplugin"><?php esc_html_e( 'Watch the Guided Tour videos', 'woocommerce' ); ?></a></li> 
  731. <li class="newsletter"><a href="https://woocommerce.com/woocommerce-onboarding-email/?utm_source=setupwizard&utm_medium=product&utm_content=newsletter&utm_campaign=woocommerceplugin"><?php esc_html_e( 'Get eCommerce advice in your inbox', 'woocommerce' ); ?></a></li> 
  732. <li class="learn-more"><a href="https://docs.woocommerce.com/documentation/plugins/woocommerce/getting-started/?utm_source=setupwizard&utm_medium=product&utm_content=docs&utm_campaign=woocommerceplugin"><?php esc_html_e( 'Learn more about getting started', 'woocommerce' ); ?></a></li> 
  733. </ul> 
  734. </div> 
  735. </div> 
  736. <?php