class-wc-settings-general.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <?php
  2. /**
  3. * WooCommerce General Settings
  4. *
  5. * @package WooCommerce/Admin
  6. */
  7. defined( 'ABSPATH' ) || exit;
  8. if ( class_exists( 'WC_Settings_General', false ) ) {
  9. return new WC_Settings_General();
  10. }
  11. /**
  12. * WC_Admin_Settings_General.
  13. */
  14. class WC_Settings_General extends WC_Settings_Page {
  15. /**
  16. * Constructor.
  17. */
  18. public function __construct() {
  19. $this->id = 'general';
  20. $this->label = __( 'General', 'woocommerce' );
  21. parent::__construct();
  22. }
  23. /**
  24. * Get settings array.
  25. *
  26. * @return array
  27. */
  28. public function get_settings() {
  29. $currency_code_options = get_woocommerce_currencies();
  30. foreach ( $currency_code_options as $code => $name ) {
  31. $currency_code_options[ $code ] = $name . ' (' . get_woocommerce_currency_symbol( $code ) . ')';
  32. }
  33. $woocommerce_default_customer_address_options = array(
  34. '' => __( 'No location by default', 'woocommerce' ),
  35. 'base' => __( 'Shop base address', 'woocommerce' ),
  36. 'geolocation' => __( 'Geolocate', 'woocommerce' ),
  37. 'geolocation_ajax' => __( 'Geolocate (with page caching support)', 'woocommerce' ),
  38. );
  39. if ( version_compare( PHP_VERSION, '5.4', '<' ) ) {
  40. unset( $woocommerce_default_customer_address_options['geolocation'], $woocommerce_default_customer_address_options['geolocation_ajax'] );
  41. }
  42. $settings = apply_filters(
  43. 'woocommerce_general_settings', array(
  44. array(
  45. 'title' => __( 'Store Address', 'woocommerce' ),
  46. 'type' => 'title',
  47. 'desc' => __( 'This is where your business is located. Tax rates and shipping rates will use this address.', 'woocommerce' ),
  48. 'id' => 'store_address',
  49. ),
  50. array(
  51. 'title' => __( 'Address line 1', 'woocommerce' ),
  52. 'desc' => __( 'The street address for your business location.', 'woocommerce' ),
  53. 'id' => 'woocommerce_store_address',
  54. 'default' => '',
  55. 'type' => 'text',
  56. 'desc_tip' => true,
  57. ),
  58. array(
  59. 'title' => __( 'Address line 2', 'woocommerce' ),
  60. 'desc' => __( 'An additional, optional address line for your business location.', 'woocommerce' ),
  61. 'id' => 'woocommerce_store_address_2',
  62. 'default' => '',
  63. 'type' => 'text',
  64. 'desc_tip' => true,
  65. ),
  66. array(
  67. 'title' => __( 'City', 'woocommerce' ),
  68. 'desc' => __( 'The city in which your business is located.', 'woocommerce' ),
  69. 'id' => 'woocommerce_store_city',
  70. 'default' => '',
  71. 'type' => 'text',
  72. 'desc_tip' => true,
  73. ),
  74. array(
  75. 'title' => __( 'Country / State', 'woocommerce' ),
  76. 'desc' => __( 'The country and state or province, if any, in which your business is located.', 'woocommerce' ),
  77. 'id' => 'woocommerce_default_country',
  78. 'default' => 'GB',
  79. 'type' => 'single_select_country',
  80. 'desc_tip' => true,
  81. ),
  82. array(
  83. 'title' => __( 'Postcode / ZIP', 'woocommerce' ),
  84. 'desc' => __( 'The postal code, if any, in which your business is located.', 'woocommerce' ),
  85. 'id' => 'woocommerce_store_postcode',
  86. 'css' => 'min-width:50px;',
  87. 'default' => '',
  88. 'type' => 'text',
  89. 'desc_tip' => true,
  90. ),
  91. array(
  92. 'type' => 'sectionend',
  93. 'id' => 'store_address',
  94. ),
  95. array(
  96. 'title' => __( 'General options', 'woocommerce' ),
  97. 'type' => 'title',
  98. 'desc' => '',
  99. 'id' => 'general_options',
  100. ),
  101. array(
  102. 'title' => __( 'Selling location(s)', 'woocommerce' ),
  103. 'desc' => __( 'This option lets you limit which countries you are willing to sell to.', 'woocommerce' ),
  104. 'id' => 'woocommerce_allowed_countries',
  105. 'default' => 'all',
  106. 'type' => 'select',
  107. 'class' => 'wc-enhanced-select',
  108. 'css' => 'min-width: 350px;',
  109. 'desc_tip' => true,
  110. 'options' => array(
  111. 'all' => __( 'Sell to all countries', 'woocommerce' ),
  112. 'all_except' => __( 'Sell to all countries, except for&hellip;', 'woocommerce' ),
  113. 'specific' => __( 'Sell to specific countries', 'woocommerce' ),
  114. ),
  115. ),
  116. array(
  117. 'title' => __( 'Sell to all countries, except for&hellip;', 'woocommerce' ),
  118. 'desc' => '',
  119. 'id' => 'woocommerce_all_except_countries',
  120. 'css' => 'min-width: 350px;',
  121. 'default' => '',
  122. 'type' => 'multi_select_countries',
  123. ),
  124. array(
  125. 'title' => __( 'Sell to specific countries', 'woocommerce' ),
  126. 'desc' => '',
  127. 'id' => 'woocommerce_specific_allowed_countries',
  128. 'css' => 'min-width: 350px;',
  129. 'default' => '',
  130. 'type' => 'multi_select_countries',
  131. ),
  132. array(
  133. 'title' => __( 'Shipping location(s)', 'woocommerce' ),
  134. 'desc' => __( 'Choose which countries you want to ship to, or choose to ship to all locations you sell to.', 'woocommerce' ),
  135. 'id' => 'woocommerce_ship_to_countries',
  136. 'default' => '',
  137. 'type' => 'select',
  138. 'class' => 'wc-enhanced-select',
  139. 'desc_tip' => true,
  140. 'options' => array(
  141. '' => __( 'Ship to all countries you sell to', 'woocommerce' ),
  142. 'all' => __( 'Ship to all countries', 'woocommerce' ),
  143. 'specific' => __( 'Ship to specific countries only', 'woocommerce' ),
  144. 'disabled' => __( 'Disable shipping &amp; shipping calculations', 'woocommerce' ),
  145. ),
  146. ),
  147. array(
  148. 'title' => __( 'Ship to specific countries', 'woocommerce' ),
  149. 'desc' => '',
  150. 'id' => 'woocommerce_specific_ship_to_countries',
  151. 'css' => '',
  152. 'default' => '',
  153. 'type' => 'multi_select_countries',
  154. ),
  155. array(
  156. 'title' => __( 'Default customer location', 'woocommerce' ),
  157. 'id' => 'woocommerce_default_customer_address',
  158. 'desc_tip' => __( 'This option determines a customers default location. The MaxMind GeoLite Database will be periodically downloaded to your wp-content directory if using geolocation.', 'woocommerce' ),
  159. 'default' => 'geolocation',
  160. 'type' => 'select',
  161. 'class' => 'wc-enhanced-select',
  162. 'options' => $woocommerce_default_customer_address_options,
  163. ),
  164. array(
  165. 'title' => __( 'Enable taxes', 'woocommerce' ),
  166. 'desc' => __( 'Enable tax rates and calculations', 'woocommerce' ),
  167. 'id' => 'woocommerce_calc_taxes',
  168. 'default' => 'no',
  169. 'type' => 'checkbox',
  170. 'desc_tip' => __( 'Rates will be configurable and taxes will be calculated during checkout.', 'woocommerce' ),
  171. ),
  172. array(
  173. 'title' => __( 'Enable coupons', 'woocommerce' ),
  174. 'desc' => __( 'Enable the use of coupon codes', 'woocommerce' ),
  175. 'id' => 'woocommerce_enable_coupons',
  176. 'default' => 'yes',
  177. 'type' => 'checkbox',
  178. 'checkboxgroup' => 'start',
  179. 'show_if_checked' => 'option',
  180. 'desc_tip' => __( 'Coupons can be applied from the cart and checkout pages.', 'woocommerce' ),
  181. ),
  182. array(
  183. 'desc' => __( 'Calculate coupon discounts sequentially', 'woocommerce' ),
  184. 'id' => 'woocommerce_calc_discounts_sequentially',
  185. 'default' => 'no',
  186. 'type' => 'checkbox',
  187. 'desc_tip' => __( 'When applying multiple coupons, apply the first coupon to the full price and the second coupon to the discounted price and so on.', 'woocommerce' ),
  188. 'show_if_checked' => 'yes',
  189. 'checkboxgroup' => 'end',
  190. 'autoload' => false,
  191. ),
  192. array(
  193. 'type' => 'sectionend',
  194. 'id' => 'general_options',
  195. ),
  196. array(
  197. 'title' => __( 'Currency options', 'woocommerce' ),
  198. 'type' => 'title',
  199. 'desc' => __( 'The following options affect how prices are displayed on the frontend.', 'woocommerce' ),
  200. 'id' => 'pricing_options',
  201. ),
  202. array(
  203. 'title' => __( 'Currency', 'woocommerce' ),
  204. 'desc' => __( 'This controls what currency prices are listed at in the catalog and which currency gateways will take payments in.', 'woocommerce' ),
  205. 'id' => 'woocommerce_currency',
  206. 'default' => 'GBP',
  207. 'type' => 'select',
  208. 'class' => 'wc-enhanced-select',
  209. 'desc_tip' => true,
  210. 'options' => $currency_code_options,
  211. ),
  212. array(
  213. 'title' => __( 'Currency position', 'woocommerce' ),
  214. 'desc' => __( 'This controls the position of the currency symbol.', 'woocommerce' ),
  215. 'id' => 'woocommerce_currency_pos',
  216. 'class' => 'wc-enhanced-select',
  217. 'default' => 'left',
  218. 'type' => 'select',
  219. 'options' => array(
  220. 'left' => __( 'Left', 'woocommerce' ),
  221. 'right' => __( 'Right', 'woocommerce' ),
  222. 'left_space' => __( 'Left with space', 'woocommerce' ),
  223. 'right_space' => __( 'Right with space', 'woocommerce' ),
  224. ),
  225. 'desc_tip' => true,
  226. ),
  227. array(
  228. 'title' => __( 'Thousand separator', 'woocommerce' ),
  229. 'desc' => __( 'This sets the thousand separator of displayed prices.', 'woocommerce' ),
  230. 'id' => 'woocommerce_price_thousand_sep',
  231. 'css' => 'width:50px;',
  232. 'default' => ',',
  233. 'type' => 'text',
  234. 'desc_tip' => true,
  235. ),
  236. array(
  237. 'title' => __( 'Decimal separator', 'woocommerce' ),
  238. 'desc' => __( 'This sets the decimal separator of displayed prices.', 'woocommerce' ),
  239. 'id' => 'woocommerce_price_decimal_sep',
  240. 'css' => 'width:50px;',
  241. 'default' => '.',
  242. 'type' => 'text',
  243. 'desc_tip' => true,
  244. ),
  245. array(
  246. 'title' => __( 'Number of decimals', 'woocommerce' ),
  247. 'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'woocommerce' ),
  248. 'id' => 'woocommerce_price_num_decimals',
  249. 'css' => 'width:50px;',
  250. 'default' => '2',
  251. 'desc_tip' => true,
  252. 'type' => 'number',
  253. 'custom_attributes' => array(
  254. 'min' => 0,
  255. 'step' => 1,
  256. ),
  257. ),
  258. array(
  259. 'type' => 'sectionend',
  260. 'id' => 'pricing_options',
  261. ),
  262. )
  263. );
  264. return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings );
  265. }
  266. /**
  267. * Output a color picker input box.
  268. *
  269. * @param mixed $name Name of input.
  270. * @param string $id ID of input.
  271. * @param mixed $value Value of input.
  272. * @param string $desc (default: '') Description for input.
  273. */
  274. public function color_picker( $name, $id, $value, $desc = '' ) {
  275. echo '<div class="color_box">' . wc_help_tip( $desc ) . '
  276. <input name="' . esc_attr( $id ) . '" id="' . esc_attr( $id ) . '" type="text" value="' . esc_attr( $value ) . '" class="colorpick" /> <div id="colorPickerDiv_' . esc_attr( $id ) . '" class="colorpickdiv"></div>
  277. </div>';
  278. }
  279. /**
  280. * Show a notice showing where the store notice setting has moved.
  281. *
  282. * @since 3.3.1
  283. * @todo remove in next major release.
  284. */
  285. private function store_notice_setting_moved_notice() {
  286. if ( get_user_meta( get_current_user_id(), 'dismissed_store_notice_setting_moved_notice', true ) ) {
  287. return;
  288. }
  289. ?>
  290. <div id="message" class="updated woocommerce-message inline">
  291. <a class="woocommerce-message-close notice-dismiss" style="top:0;" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-hide-notice', 'store_notice_setting_moved' ), 'woocommerce_hide_notices_nonce', '_wc_notice_nonce' ) ); ?>"><?php esc_html_e( 'Dismiss', 'woocommerce' ); ?></a>
  292. <p>
  293. <?php
  294. echo wp_kses(
  295. sprintf(
  296. /* translators: %s: URL to customizer. */
  297. __( 'Looking for the store notice setting? It can now be found <a href="%s">in the Customizer</a>.', 'woocommerce' ), esc_url(
  298. add_query_arg(
  299. array(
  300. 'autofocus' => array(
  301. 'panel' => 'woocommerce',
  302. ),
  303. 'url' => wc_get_page_permalink( 'shop' ),
  304. ), admin_url( 'customize.php' )
  305. )
  306. )
  307. ), array(
  308. 'a' => array(
  309. 'href' => array(),
  310. 'title' => array(),
  311. ),
  312. )
  313. );
  314. ?>
  315. </p>
  316. </div>
  317. <?php
  318. }
  319. /**
  320. * Output the settings.
  321. */
  322. public function output() {
  323. $settings = $this->get_settings();
  324. $this->store_notice_setting_moved_notice();
  325. WC_Admin_Settings::output_fields( $settings );
  326. }
  327. /**
  328. * Save settings.
  329. */
  330. public function save() {
  331. $settings = $this->get_settings();
  332. WC_Admin_Settings::save_fields( $settings );
  333. }
  334. }
  335. return new WC_Settings_General();