WC_Settings_Products

WC_Settings_Products.

Defined (1)

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

/includes/admin/settings/class-wc-settings-products.php  
  1. class WC_Settings_Products extends WC_Settings_Page { 
  2.  
  3. /** 
  4. * Constructor. 
  5. */ 
  6. public function __construct() { 
  7.  
  8. $this->id = 'products'; 
  9. $this->label = __( 'Products', 'woocommerce' ); 
  10.  
  11. add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); 
  12. add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) ); 
  13. add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) ); 
  14. add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) ); 
  15.  
  16. /** 
  17. * Get sections. 
  18. * @return array 
  19. */ 
  20. public function get_sections() { 
  21.  
  22. $sections = array( 
  23. '' => __( 'General', 'woocommerce' ),  
  24. 'display' => __( 'Display', 'woocommerce' ),  
  25. 'inventory' => __( 'Inventory', 'woocommerce' ),  
  26. 'downloadable' => __( 'Downloadable products', 'woocommerce' ),  
  27. ); 
  28.  
  29. return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections ); 
  30.  
  31. /** 
  32. * Output the settings. 
  33. */ 
  34. public function output() { 
  35. global $current_section; 
  36.  
  37. $settings = $this->get_settings( $current_section ); 
  38.  
  39. WC_Admin_Settings::output_fields( $settings ); 
  40.  
  41. /** 
  42. * Save settings. 
  43. */ 
  44. public function save() { 
  45. global $current_section; 
  46.  
  47. $settings = $this->get_settings( $current_section ); 
  48. WC_Admin_Settings::save_fields( $settings ); 
  49.  
  50. /** 
  51. * Get settings array. 
  52. * @return array 
  53. */ 
  54. public function get_settings( $current_section = '' ) { 
  55. if ( 'display' == $current_section ) { 
  56.  
  57. $settings = apply_filters( 'woocommerce_product_settings', array( 
  58.  
  59. array( 
  60. 'title' => __( 'Shop & product pages', 'woocommerce' ),  
  61. 'type' => 'title',  
  62. 'desc' => '',  
  63. 'id' => 'catalog_options',  
  64. ),  
  65.  
  66. array( 
  67. 'title' => __( 'Shop page', 'woocommerce' ),  
  68. 'desc' => '<br/>' . sprintf( __( 'The base page can also be used in your <a href="%s">product permalinks</a>.', 'woocommerce' ), admin_url( 'options-permalink.php' ) ),  
  69. 'id' => 'woocommerce_shop_page_id',  
  70. 'type' => 'single_select_page',  
  71. 'default' => '',  
  72. 'class' => 'wc-enhanced-select-nostd',  
  73. 'css' => 'min-width:300px;',  
  74. 'desc_tip' => __( 'This sets the base page of your shop - this is where your product archive will be.', 'woocommerce' ),  
  75. ),  
  76.  
  77. array( 
  78. 'title' => __( 'Shop page display', 'woocommerce' ),  
  79. 'desc' => __( 'This controls what is shown on the product archive.', 'woocommerce' ),  
  80. 'id' => 'woocommerce_shop_page_display',  
  81. 'class' => 'wc-enhanced-select',  
  82. 'css' => 'min-width:300px;',  
  83. 'default' => '',  
  84. 'type' => 'select',  
  85. 'options' => array( 
  86. '' => __( 'Show products', 'woocommerce' ),  
  87. 'subcategories' => __( 'Show categories', 'woocommerce' ),  
  88. 'both' => __( 'Show categories & products', 'woocommerce' ),  
  89. ),  
  90. 'desc_tip' => true,  
  91. ),  
  92.  
  93. array( 
  94. 'title' => __( 'Default category display', 'woocommerce' ),  
  95. 'desc' => __( 'This controls what is shown on category archives.', 'woocommerce' ),  
  96. 'id' => 'woocommerce_category_archive_display',  
  97. 'class' => 'wc-enhanced-select',  
  98. 'css' => 'min-width:300px;',  
  99. 'default' => '',  
  100. 'type' => 'select',  
  101. 'options' => array( 
  102. '' => __( 'Show products', 'woocommerce' ),  
  103. 'subcategories' => __( 'Show subcategories', 'woocommerce' ),  
  104. 'both' => __( 'Show subcategories & products', 'woocommerce' ),  
  105. ),  
  106. 'desc_tip' => true,  
  107. ),  
  108.  
  109. array( 
  110. 'title' => __( 'Default product sorting', 'woocommerce' ),  
  111. 'desc' => __( 'This controls the default sort order of the catalog.', 'woocommerce' ),  
  112. 'id' => 'woocommerce_default_catalog_orderby',  
  113. 'class' => 'wc-enhanced-select',  
  114. 'css' => 'min-width:300px;',  
  115. 'default' => 'menu_order',  
  116. 'type' => 'select',  
  117. 'options' => apply_filters( 'woocommerce_default_catalog_orderby_options', array( 
  118. 'menu_order' => __( 'Default sorting (custom ordering + name)', 'woocommerce' ),  
  119. 'popularity' => __( 'Popularity (sales)', 'woocommerce' ),  
  120. 'rating' => __( 'Average rating', 'woocommerce' ),  
  121. 'date' => __( 'Sort by most recent', 'woocommerce' ),  
  122. 'price' => __( 'Sort by price (asc)', 'woocommerce' ),  
  123. 'price-desc' => __( 'Sort by price (desc)', 'woocommerce' ),  
  124. ) ),  
  125. 'desc_tip' => true,  
  126. ),  
  127.  
  128. array( 
  129. 'title' => __( 'Add to cart behaviour', 'woocommerce' ),  
  130. 'desc' => __( 'Redirect to the cart page after successful addition', 'woocommerce' ),  
  131. 'id' => 'woocommerce_cart_redirect_after_add',  
  132. 'default' => 'no',  
  133. 'type' => 'checkbox',  
  134. 'checkboxgroup' => 'start',  
  135. ),  
  136.  
  137. array( 
  138. 'desc' => __( 'Enable AJAX add to cart buttons on archives', 'woocommerce' ),  
  139. 'id' => 'woocommerce_enable_ajax_add_to_cart',  
  140. 'default' => 'yes',  
  141. 'type' => 'checkbox',  
  142. 'checkboxgroup' => 'end',  
  143. ),  
  144.  
  145. array( 
  146. 'type' => 'sectionend',  
  147. 'id' => 'catalog_options',  
  148. ),  
  149.  
  150. array( 
  151. 'title' => __( 'Product images', 'woocommerce' ),  
  152. 'type' => 'title',  
  153. 'desc' => sprintf( __( 'These settings affect the display and dimensions of images in your catalog - the display on the front-end will still be affected by CSS styles. After changing these settings you may need to <a target="_blank" href="%s">regenerate your thumbnails</a>.', 'woocommerce' ), 'https://wordpress.org/plugins/regenerate-thumbnails/' ),  
  154. 'id' => 'image_options',  
  155. ),  
  156.  
  157. array( 
  158. 'title' => __( 'Catalog images', 'woocommerce' ),  
  159. 'desc' => __( 'This size is usually used in product listings. (W x H)', 'woocommerce' ),  
  160. 'id' => 'shop_catalog_image_size',  
  161. 'css' => '',  
  162. 'type' => 'image_width',  
  163. 'default' => array( 
  164. 'width' => '300',  
  165. 'height' => '300',  
  166. 'crop' => 1,  
  167. ),  
  168. 'desc_tip' => true,  
  169. ),  
  170.  
  171. array( 
  172. 'title' => __( 'Single product image', 'woocommerce' ),  
  173. 'desc' => __( 'This is the size used by the main image on the product page. (W x H)', 'woocommerce' ),  
  174. 'id' => 'shop_single_image_size',  
  175. 'css' => '',  
  176. 'type' => 'image_width',  
  177. 'default' => array( 
  178. 'width' => '600',  
  179. 'height' => '600',  
  180. 'crop' => 1,  
  181. ),  
  182. 'desc_tip' => true,  
  183. ),  
  184.  
  185. array( 
  186. 'title' => __( 'Product thumbnails', 'woocommerce' ),  
  187. 'desc' => __( 'This size is usually used for the gallery of images on the product page. (W x H)', 'woocommerce' ),  
  188. 'id' => 'shop_thumbnail_image_size',  
  189. 'css' => '',  
  190. 'type' => 'image_width',  
  191. 'default' => array( 
  192. 'width' => '180',  
  193. 'height' => '180',  
  194. 'crop' => 1,  
  195. ),  
  196. 'desc_tip' => true,  
  197. ),  
  198.  
  199. array( 
  200. 'type' => 'sectionend',  
  201. 'id' => 'image_options',  
  202. ),  
  203.  
  204. )); 
  205. } elseif ( 'inventory' == $current_section ) { 
  206.  
  207. $settings = apply_filters( 'woocommerce_inventory_settings', array( 
  208.  
  209. array( 
  210. 'title' => __( 'Inventory', 'woocommerce' ),  
  211. 'type' => 'title',  
  212. 'desc' => '',  
  213. 'id' => 'product_inventory_options',  
  214. ),  
  215.  
  216. array( 
  217. 'title' => __( 'Manage stock', 'woocommerce' ),  
  218. 'desc' => __( 'Enable stock management', 'woocommerce' ),  
  219. 'id' => 'woocommerce_manage_stock',  
  220. 'default' => 'yes',  
  221. 'type' => 'checkbox',  
  222. ),  
  223.  
  224. array( 
  225. 'title' => __( 'Hold stock (minutes)', 'woocommerce' ),  
  226. 'desc' => __( 'Hold stock (for unpaid orders) for x minutes. When this limit is reached, the pending order will be cancelled. Leave blank to disable.', 'woocommerce' ),  
  227. 'id' => 'woocommerce_hold_stock_minutes',  
  228. 'type' => 'number',  
  229. 'custom_attributes' => array( 
  230. 'min' => 0,  
  231. 'step' => 1,  
  232. ),  
  233. 'css' => 'width: 80px;',  
  234. 'default' => '60',  
  235. 'autoload' => false,  
  236. 'class' => 'manage_stock_field',  
  237. ),  
  238.  
  239. array( 
  240. 'title' => __( 'Notifications', 'woocommerce' ),  
  241. 'desc' => __( 'Enable low stock notifications', 'woocommerce' ),  
  242. 'id' => 'woocommerce_notify_low_stock',  
  243. 'default' => 'yes',  
  244. 'type' => 'checkbox',  
  245. 'checkboxgroup' => 'start',  
  246. 'autoload' => false,  
  247. 'class' => 'manage_stock_field',  
  248. ),  
  249.  
  250. array( 
  251. 'desc' => __( 'Enable out of stock notifications', 'woocommerce' ),  
  252. 'id' => 'woocommerce_notify_no_stock',  
  253. 'default' => 'yes',  
  254. 'type' => 'checkbox',  
  255. 'checkboxgroup' => 'end',  
  256. 'autoload' => false,  
  257. 'class' => 'manage_stock_field',  
  258. ),  
  259.  
  260. array( 
  261. 'title' => __( 'Notification recipient(s)', 'woocommerce' ),  
  262. 'desc' => __( 'Enter recipients (comma separated) that will receive this notification.', 'woocommerce' ),  
  263. 'id' => 'woocommerce_stock_email_recipient',  
  264. 'type' => 'text',  
  265. 'default' => get_option( 'admin_email' ),  
  266. 'css' => 'width: 250px;',  
  267. 'autoload' => false,  
  268. 'desc_tip' => true,  
  269. 'class' => 'manage_stock_field',  
  270. ),  
  271.  
  272. array( 
  273. 'title' => __( 'Low stock threshold', 'woocommerce' ),  
  274. 'desc' => __( 'When product stock reaches this amount you will be notified via email.', 'woocommerce' ),  
  275. 'id' => 'woocommerce_notify_low_stock_amount',  
  276. 'css' => 'width:50px;',  
  277. 'type' => 'number',  
  278. 'custom_attributes' => array( 
  279. 'min' => 0,  
  280. 'step' => 1,  
  281. ),  
  282. 'default' => '2',  
  283. 'autoload' => false,  
  284. 'desc_tip' => true,  
  285. 'class' => 'manage_stock_field',  
  286. ),  
  287.  
  288. array( 
  289. 'title' => __( 'Out of stock threshold', 'woocommerce' ),  
  290. 'desc' => __( 'When product stock reaches this amount the stock status will change to "out of stock" and you will be notified via email. This setting does not affect existing "in stock" products.', 'woocommerce' ),  
  291. 'id' => 'woocommerce_notify_no_stock_amount',  
  292. 'css' => 'width:50px;',  
  293. 'type' => 'number',  
  294. 'custom_attributes' => array( 
  295. 'min' => 0,  
  296. 'step' => 1,  
  297. ),  
  298. 'default' => '0',  
  299. 'desc_tip' => true,  
  300. 'class' => 'manage_stock_field',  
  301. ),  
  302.  
  303. array( 
  304. 'title' => __( 'Out of stock visibility', 'woocommerce' ),  
  305. 'desc' => __( 'Hide out of stock items from the catalog', 'woocommerce' ),  
  306. 'id' => 'woocommerce_hide_out_of_stock_items',  
  307. 'default' => 'no',  
  308. 'type' => 'checkbox',  
  309. ),  
  310.  
  311. array( 
  312. 'title' => __( 'Stock display format', 'woocommerce' ),  
  313. 'desc' => __( 'This controls how stock quantities are displayed on the frontend.', 'woocommerce' ),  
  314. 'id' => 'woocommerce_stock_format',  
  315. 'css' => 'min-width:150px;',  
  316. 'class' => 'wc-enhanced-select',  
  317. 'default' => '',  
  318. 'type' => 'select',  
  319. 'options' => array( 
  320. '' => __( 'Always show quantity remaining in stock e.g. "12 in stock"', 'woocommerce' ),  
  321. 'low_amount' => __( 'Only show quantity remaining in stock when low e.g. "Only 2 left in stock"', 'woocommerce' ),  
  322. 'no_amount' => __( 'Never show quantity remaining in stock', 'woocommerce' ),  
  323. ),  
  324. 'desc_tip' => true,  
  325. ),  
  326.  
  327. array( 
  328. 'type' => 'sectionend',  
  329. 'id' => 'product_inventory_options',  
  330. ),  
  331.  
  332. )); 
  333.  
  334. } elseif ( 'downloadable' == $current_section ) { 
  335. $settings = apply_filters( 'woocommerce_downloadable_products_settings', array( 
  336. array( 
  337. 'title' => __( 'Downloadable products', 'woocommerce' ),  
  338. 'type' => 'title',  
  339. 'id' => 'digital_download_options',  
  340. ),  
  341.  
  342. array( 
  343. 'title' => __( 'File download method', 'woocommerce' ),  
  344. 'desc' => __( 'Forcing downloads will keep URLs hidden, but some servers may serve large files unreliably. If supported, <code>X-Accel-Redirect</code>/ <code>X-Sendfile</code> can be used to serve downloads instead (server requires <code>mod_xsendfile</code>).', 'woocommerce' ),  
  345. 'id' => 'woocommerce_file_download_method',  
  346. 'type' => 'select',  
  347. 'class' => 'wc-enhanced-select',  
  348. 'css' => 'min-width:300px;',  
  349. 'default' => 'force',  
  350. 'desc_tip' => true,  
  351. 'options' => array( 
  352. 'force' => __( 'Force downloads', 'woocommerce' ),  
  353. 'xsendfile' => __( 'X-Accel-Redirect/X-Sendfile', 'woocommerce' ),  
  354. 'redirect' => __( 'Redirect only', 'woocommerce' ),  
  355. ),  
  356. 'autoload' => false,  
  357. ),  
  358.  
  359. array( 
  360. 'title' => __( 'Access restriction', 'woocommerce' ),  
  361. 'desc' => __( 'Downloads require login', 'woocommerce' ),  
  362. 'id' => 'woocommerce_downloads_require_login',  
  363. 'type' => 'checkbox',  
  364. 'default' => 'no',  
  365. 'desc_tip' => __( 'This setting does not apply to guest purchases.', 'woocommerce' ),  
  366. 'checkboxgroup' => 'start',  
  367. 'autoload' => false,  
  368. ),  
  369.  
  370. array( 
  371. 'desc' => __( 'Grant access to downloadable products after payment', 'woocommerce' ),  
  372. 'id' => 'woocommerce_downloads_grant_access_after_payment',  
  373. 'type' => 'checkbox',  
  374. 'default' => 'yes',  
  375. 'desc_tip' => __( 'Enable this option to grant access to downloads when orders are "processing", rather than "completed".', 'woocommerce' ),  
  376. 'checkboxgroup' => 'end',  
  377. 'autoload' => false,  
  378. ),  
  379.  
  380. array( 
  381. 'type' => 'sectionend',  
  382. 'id' => 'digital_download_options',  
  383. ),  
  384.  
  385. )); 
  386.  
  387. } else { 
  388. $settings = apply_filters( 'woocommerce_products_general_settings', array( 
  389. array( 
  390. 'title' => __( 'Measurements', 'woocommerce' ),  
  391. 'type' => 'title',  
  392. 'id' => 'product_measurement_options',  
  393. ),  
  394.  
  395. array( 
  396. 'title' => __( 'Weight unit', 'woocommerce' ),  
  397. 'desc' => __( 'This controls what unit you will define weights in.', 'woocommerce' ),  
  398. 'id' => 'woocommerce_weight_unit',  
  399. 'class' => 'wc-enhanced-select',  
  400. 'css' => 'min-width:300px;',  
  401. 'default' => 'kg',  
  402. 'type' => 'select',  
  403. 'options' => array( 
  404. 'kg' => __( 'kg', 'woocommerce' ),  
  405. 'g' => __( 'g', 'woocommerce' ),  
  406. 'lbs' => __( 'lbs', 'woocommerce' ),  
  407. 'oz' => __( 'oz', 'woocommerce' ),  
  408. ),  
  409. 'desc_tip' => true,  
  410. ),  
  411.  
  412. array( 
  413. 'title' => __( 'Dimensions unit', 'woocommerce' ),  
  414. 'desc' => __( 'This controls what unit you will define lengths in.', 'woocommerce' ),  
  415. 'id' => 'woocommerce_dimension_unit',  
  416. 'class' => 'wc-enhanced-select',  
  417. 'css' => 'min-width:300px;',  
  418. 'default' => 'cm',  
  419. 'type' => 'select',  
  420. 'options' => array( 
  421. 'm' => __( 'm', 'woocommerce' ),  
  422. 'cm' => __( 'cm', 'woocommerce' ),  
  423. 'mm' => __( 'mm', 'woocommerce' ),  
  424. 'in' => __( 'in', 'woocommerce' ),  
  425. 'yd' => __( 'yd', 'woocommerce' ),  
  426. ),  
  427. 'desc_tip' => true,  
  428. ),  
  429.  
  430. array( 
  431. 'type' => 'sectionend',  
  432. 'id' => 'product_measurement_options',  
  433. ),  
  434.  
  435. array( 
  436. 'title' => __( 'Reviews', 'woocommerce' ),  
  437. 'type' => 'title',  
  438. 'desc' => '',  
  439. 'id' => 'product_rating_options',  
  440. ),  
  441.  
  442. array( 
  443. 'title' => __( 'Product ratings', 'woocommerce' ),  
  444. 'desc' => __( 'Enable ratings on reviews', 'woocommerce' ),  
  445. 'id' => 'woocommerce_enable_review_rating',  
  446. 'default' => 'yes',  
  447. 'type' => 'checkbox',  
  448. 'checkboxgroup' => 'start',  
  449. 'show_if_checked' => 'option',  
  450. ),  
  451.  
  452. array( 
  453. 'desc' => __( 'Ratings are required to leave a review', 'woocommerce' ),  
  454. 'id' => 'woocommerce_review_rating_required',  
  455. 'default' => 'yes',  
  456. 'type' => 'checkbox',  
  457. 'checkboxgroup' => '',  
  458. 'show_if_checked' => 'yes',  
  459. 'autoload' => false,  
  460. ),  
  461.  
  462. array( 
  463. 'desc' => __( 'Show "verified owner" label for customer reviews', 'woocommerce' ),  
  464. 'id' => 'woocommerce_review_rating_verification_label',  
  465. 'default' => 'yes',  
  466. 'type' => 'checkbox',  
  467. 'checkboxgroup' => '',  
  468. 'show_if_checked' => 'yes',  
  469. 'autoload' => false,  
  470. ),  
  471.  
  472. array( 
  473. 'desc' => __( 'Only allow reviews from "verified owners"', 'woocommerce' ),  
  474. 'id' => 'woocommerce_review_rating_verification_required',  
  475. 'default' => 'no',  
  476. 'type' => 'checkbox',  
  477. 'checkboxgroup' => 'end',  
  478. 'show_if_checked' => 'yes',  
  479. 'autoload' => false,  
  480. ),  
  481.  
  482. array( 
  483. 'type' => 'sectionend',  
  484. 'id' => 'product_rating_options',  
  485. ),  
  486.  
  487. )); 
  488.  
  489. return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );