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