1 <?php
  2 /**
  3  * WooCommerce Product Settings
  4  *
  5  * @author      WooThemes
  6  * @category    Admin
  7  * @package     WooCommerce/Admin
  8  * @version     2.1.0
  9  */
 10 
 11 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
 12 
 13 if ( ! class_exists( 'WC_Settings_Products' ) ) :
 14 
 15 /**
 16  * WC_Settings_Products
 17  */
 18 class WC_Settings_Products extends WC_Settings_Page {
 19 
 20     /**
 21      * Constructor.
 22      */
 23     public function __construct() {
 24         $this->id    = 'products';
 25         $this->label = __( 'Products', 'woocommerce' );
 26 
 27         add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
 28         add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
 29         add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
 30         add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) );
 31     }
 32 
 33     /**
 34      * Get sections
 35      *
 36      * @return array
 37      */
 38     public function get_sections() {
 39         $sections = array(
 40             ''          => __( 'Product Options', 'woocommerce' ),
 41             'inventory' => __( 'Inventory', 'woocommerce' )
 42         );
 43 
 44         return $sections;
 45     }
 46 
 47     /**
 48      * Output the settings
 49      */
 50     public function output() {
 51         global $current_section;
 52 
 53         $settings = $this->get_settings( $current_section );
 54 
 55         WC_Admin_Settings::output_fields( $settings );
 56     }
 57 
 58     /**
 59      * Save settings
 60      */
 61     public function save() {
 62         global $current_section;
 63 
 64         $settings = $this->get_settings( $current_section );
 65         WC_Admin_Settings::save_fields( $settings );
 66     }
 67 
 68     /**
 69      * Get settings array
 70      *
 71      * @return array
 72      */
 73     public function get_settings( $current_section = '' ) {
 74 
 75         if ( $current_section == 'inventory' ) {
 76 
 77             return apply_filters('woocommerce_inventory_settings', array(
 78 
 79                 array(  'title' => __( 'Inventory Options', 'woocommerce' ), 'type' => 'title', 'desc' => '', 'id' => 'inventory_options' ),
 80 
 81                 array(
 82                     'title' => __( 'Manage Stock', 'woocommerce' ),
 83                     'desc'      => __( 'Enable stock management', 'woocommerce' ),
 84                     'id'        => 'woocommerce_manage_stock',
 85                     'default'   => 'yes',
 86                     'type'      => 'checkbox'
 87                 ),
 88 
 89                 array(
 90                     'title' => __( 'Hold Stock (minutes)', 'woocommerce' ),
 91                     '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' ),
 92                     'id'        => 'woocommerce_hold_stock_minutes',
 93                     'type'      => 'number',
 94                     'custom_attributes' => array(
 95                         'min'   => 0,
 96                         'step'  => 1
 97                     ),
 98                     'css'       => 'width:50px;',
 99                     'default'   => '60',
100                     'autoload'  => false
101                 ),
102 
103                 array(
104                     'title' => __( 'Notifications', 'woocommerce' ),
105                     'desc'      => __( 'Enable low stock notifications', 'woocommerce' ),
106                     'id'        => 'woocommerce_notify_low_stock',
107                     'default'   => 'yes',
108                     'type'      => 'checkbox',
109                     'checkboxgroup' => 'start',
110                     'autoload'      => false
111                 ),
112 
113                 array(
114                     'desc'      => __( 'Enable out of stock notifications', 'woocommerce' ),
115                     'id'        => 'woocommerce_notify_no_stock',
116                     'default'   => 'yes',
117                     'type'      => 'checkbox',
118                     'checkboxgroup' => 'end',
119                     'autoload'      => false
120                 ),
121 
122                 array(
123                     'title' => __( 'Notification Recipient', 'woocommerce' ),
124                     'desc'      => '',
125                     'id'        => 'woocommerce_stock_email_recipient',
126                     'type'      => 'email',
127                     'default'   => get_option( 'admin_email' ),
128                     'autoload'      => false
129                 ),
130 
131                 array(
132                     'title' => __( 'Low Stock Threshold', 'woocommerce' ),
133                     'desc'      => '',
134                     'id'        => 'woocommerce_notify_low_stock_amount',
135                     'css'       => 'width:50px;',
136                     'type'      => 'number',
137                     'custom_attributes' => array(
138                         'min'   => 0,
139                         'step'  => 1
140                     ),
141                     'default'   => '2',
142                     'autoload'      => false
143                 ),
144 
145                 array(
146                     'title' => __( 'Out Of Stock Threshold', 'woocommerce' ),
147                     'desc'      => '',
148                     'id'        => 'woocommerce_notify_no_stock_amount',
149                     'css'       => 'width:50px;',
150                     'type'      => 'number',
151                     'custom_attributes' => array(
152                         'min'   => 0,
153                         'step'  => 1
154                     ),
155                     'default'   => '0',
156                     'autoload'      => false
157                 ),
158 
159                 array(
160                     'title' => __( 'Out Of Stock Visibility', 'woocommerce' ),
161                     'desc'      => __( 'Hide out of stock items from the catalog', 'woocommerce' ),
162                     'id'        => 'woocommerce_hide_out_of_stock_items',
163                     'default'   => 'no',
164                     'type'      => 'checkbox'
165                 ),
166 
167                 array(
168                     'title' => __( 'Stock Display Format', 'woocommerce' ),
169                     'desc'      => __( 'This controls how stock is displayed on the frontend.', 'woocommerce' ),
170                     'id'        => 'woocommerce_stock_format',
171                     'css'       => 'min-width:150px;',
172                     'default'   => '',
173                     'type'      => 'select',
174                     'options' => array(
175                         ''              => __( 'Always show stock e.g. "12 in stock"', 'woocommerce' ),
176                         'low_amount'    => __( 'Only show stock when low e.g. "Only 2 left in stock" vs. "In Stock"', 'woocommerce' ),
177                         'no_amount'     => __( 'Never show stock amount', 'woocommerce' ),
178                     ),
179                     'desc_tip'  =>  true,
180                 ),
181 
182                 array( 'type' => 'sectionend', 'id' => 'inventory_options'),
183 
184             ));
185 
186         } else {
187 
188             // Get shop page
189             $shop_page_id = wc_get_page_id('shop');
190 
191             $base_slug = ($shop_page_id > 0 && get_page( $shop_page_id )) ? get_page_uri( $shop_page_id ) : 'shop';
192 
193             $woocommerce_prepend_shop_page_to_products_warning = '';
194 
195             if ( $shop_page_id > 0 && sizeof(get_pages("child_of=$shop_page_id")) > 0 )
196                 $woocommerce_prepend_shop_page_to_products_warning = ' <mark class="notice">' . __( 'Note: The shop page has children - child pages will not work if you enable this option.', 'woocommerce' ) . '</mark>';
197 
198             return apply_filters( 'woocommerce_product_settings', array(
199 
200                 array(  'title' => __( 'Product Listings', 'woocommerce' ), 'type' => 'title','desc' => '', 'id' => 'catalog_options' ),
201 
202                 array(
203                     'title' => __( 'Product Archive / Shop Page', 'woocommerce' ),
204                     'desc'      => '<br/>' . sprintf( __( 'The base page can also be used in your <a href="%s">product permalinks</a>.', 'woocommerce' ), admin_url( 'options-permalink.php' ) ),
205                     'id'        => 'woocommerce_shop_page_id',
206                     'type'      => 'single_select_page',
207                     'default'   => '',
208                     'class'     => 'chosen_select_nostd',
209                     'css'       => 'min-width:300px;',
210                     'desc_tip'  => __( 'This sets the base page of your shop - this is where your product archive will be.', 'woocommerce' ),
211                 ),
212 
213                 array(
214                     'title' => __( 'Shop Page Display', 'woocommerce' ),
215                     'desc'      => __( 'This controls what is shown on the product archive.', 'woocommerce' ),
216                     'id'        => 'woocommerce_shop_page_display',
217                     'class'     => 'chosen_select',
218                     'css'       => 'min-width:300px;',
219                     'default'   => '',
220                     'type'      => 'select',
221                     'options' => array(
222                         ''              => __( 'Show products', 'woocommerce' ),
223                         'subcategories' => __( 'Show subcategories', 'woocommerce' ),
224                         'both'          => __( 'Show both', 'woocommerce' ),
225                     ),
226                     'desc_tip'  =>  true,
227                 ),
228 
229                 array(
230                     'title' => __( 'Default Category Display', 'woocommerce' ),
231                     'desc'      => __( 'This controls what is shown on category archives.', 'woocommerce' ),
232                     'id'        => 'woocommerce_category_archive_display',
233                     'class'     => 'chosen_select',
234                     'css'       => 'min-width:300px;',
235                     'default'   => '',
236                     'type'      => 'select',
237                     'options' => array(
238                         ''              => __( 'Show products', 'woocommerce' ),
239                         'subcategories' => __( 'Show subcategories', 'woocommerce' ),
240                         'both'          => __( 'Show both', 'woocommerce' ),
241                     ),
242                     'desc_tip'  =>  true,
243                 ),
244 
245                 array(
246                     'title' => __( 'Default Product Sorting', 'woocommerce' ),
247                     'desc'      => __( 'This controls the default sort order of the catalog.', 'woocommerce' ),
248                     'id'        => 'woocommerce_default_catalog_orderby',
249                     'class'     => 'chosen_select',
250                     'css'       => 'min-width:300px;',
251                     'default'   => 'title',
252                     'type'      => 'select',
253                     'options' => apply_filters('woocommerce_default_catalog_orderby_options', array(
254                         'menu_order' => __( 'Default sorting (custom ordering + name)', 'woocommerce' ),
255                         'popularity' => __( 'Popularity (sales)', 'woocommerce' ),
256                         'rating'     => __( 'Average Rating', 'woocommerce' ),
257                         'date'       => __( 'Sort by most recent', 'woocommerce' ),
258                         'price'      => __( 'Sort by price (asc)', 'woocommerce' ),
259                         'price-desc' => __( 'Sort by price (desc)', 'woocommerce' ),
260                     )),
261                     'desc_tip'  =>  true,
262                 ),
263 
264                 array(
265                     'title' => __( 'Add to cart', 'woocommerce' ),
266                     'desc'      => __( 'Redirect to the cart page after successful addition', 'woocommerce' ),
267                     'id'        => 'woocommerce_cart_redirect_after_add',
268                     'default'   => 'no',
269                     'type'      => 'checkbox',
270                     'checkboxgroup'     => 'start'
271                 ),
272 
273                 array(
274                     'desc'      => __( 'Enable AJAX add to cart buttons on archives', 'woocommerce' ),
275                     'id'        => 'woocommerce_enable_ajax_add_to_cart',
276                     'default'   => 'yes',
277                     'type'      => 'checkbox',
278                     'checkboxgroup'     => 'end'
279                 ),
280 
281                 array( 'type' => 'sectionend', 'id' => 'catalog_options' ),
282 
283                 array(  'title' => __( 'Product Data', 'woocommerce' ), 'type' => 'title', 'id' => 'product_data_options' ),
284 
285                 array(
286                     'title' => __( 'Weight Unit', 'woocommerce' ),
287                     'desc'      => __( 'This controls what unit you will define weights in.', 'woocommerce' ),
288                     'id'        => 'woocommerce_weight_unit',
289                     'class'     => 'chosen_select',
290                     'css'       => 'min-width:300px;',
291                     'default'   => 'kg',
292                     'type'      => 'select',
293                     'options' => array(
294                         'kg'  => __( 'kg', 'woocommerce' ),
295                         'g'   => __( 'g', 'woocommerce' ),
296                         'lbs' => __( 'lbs', 'woocommerce' ),
297                         'oz' => __( 'oz', 'woocommerce' ),
298                     ),
299                     'desc_tip'  =>  true,
300                 ),
301 
302                 array(
303                     'title' => __( 'Dimensions Unit', 'woocommerce' ),
304                     'desc'      => __( 'This controls what unit you will define lengths in.', 'woocommerce' ),
305                     'id'        => 'woocommerce_dimension_unit',
306                     'class'     => 'chosen_select',
307                     'css'       => 'min-width:300px;',
308                     'default'   => 'cm',
309                     'type'      => 'select',
310                     'options' => array(
311                         'm'  => __( 'm', 'woocommerce' ),
312                         'cm' => __( 'cm', 'woocommerce' ),
313                         'mm' => __( 'mm', 'woocommerce' ),
314                         'in' => __( 'in', 'woocommerce' ),
315                         'yd' => __( 'yd', 'woocommerce' ),
316                     ),
317                     'desc_tip'  =>  true,
318                 ),
319 
320                 array(
321                     'title' => __( 'Product Ratings', 'woocommerce' ),
322                     'desc'      => __( 'Enable ratings on reviews', 'woocommerce' ),
323                     'id'        => 'woocommerce_enable_review_rating',
324                     'default'   => 'yes',
325                     'type'      => 'checkbox',
326                     'checkboxgroup'     => 'start',
327                     'show_if_checked' => 'option',
328                     'autoload'      => false
329                 ),
330 
331                 array(
332                     'desc'      => __( 'Ratings are required to leave a review', 'woocommerce' ),
333                     'id'        => 'woocommerce_review_rating_required',
334                     'default'   => 'yes',
335                     'type'      => 'checkbox',
336                     'checkboxgroup'     => '',
337                     'show_if_checked' => 'yes',
338                     'autoload'      => false
339                 ),
340 
341                 array(
342                     'desc'      => __( 'Show "verified owner" label for customer reviews', 'woocommerce' ),
343                     'id'        => 'woocommerce_review_rating_verification_label',
344                     'default'   => 'yes',
345                     'type'      => 'checkbox',
346                     'checkboxgroup'     => '',
347                     'show_if_checked' => 'yes',
348                     'autoload'      => false
349                 ),
350 
351                 array(
352                     'desc'      => __( 'Only allow reviews from "verified owners"', 'woocommerce' ),
353                     'id'        => 'woocommerce_review_rating_verification_required',
354                     'default'   => 'no',
355                     'type'      => 'checkbox',
356                     'checkboxgroup'     => 'end',
357                     'show_if_checked' => 'yes',
358                     'autoload'      => false
359                 ),
360 
361                 array( 'type' => 'sectionend', 'id' => 'product_data_options' ),
362 
363                 array(  'title' => __( 'Product Image Sizes', 'woocommerce' ), 'type' => 'title','desc' => sprintf(__( 'These settings affect the actual 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 href="%s">regenerate your thumbnails</a>.', 'woocommerce' ), 'http://wordpress.org/extend/plugins/regenerate-thumbnails/'), 'id' => 'image_options' ),
364 
365                 array(
366                     'title' => __( 'Catalog Images', 'woocommerce' ),
367                     'desc'      => __( 'This size is usually used in product listings', 'woocommerce' ),
368                     'id'        => 'shop_catalog_image_size',
369                     'css'       => '',
370                     'type'      => 'image_width',
371                     'default'   => array(
372                         'width'     => '150',
373                         'height'    => '150',
374                         'crop'      => true
375                     ),
376                     'desc_tip'  =>  true,
377                 ),
378 
379                 array(
380                     'title' => __( 'Single Product Image', 'woocommerce' ),
381                     'desc'      => __( 'This is the size used by the main image on the product page.', 'woocommerce' ),
382                     'id'        => 'shop_single_image_size',
383                     'css'       => '',
384                     'type'      => 'image_width',
385                     'default'   => array(
386                         'width'     => '300',
387                         'height'    => '300',
388                         'crop'      => 1
389                     ),
390                     'desc_tip'  =>  true,
391                 ),
392 
393                 array(
394                     'title' => __( 'Product Thumbnails', 'woocommerce' ),
395                     'desc'      => __( 'This size is usually used for the gallery of images on the product page.', 'woocommerce' ),
396                     'id'        => 'shop_thumbnail_image_size',
397                     'css'       => '',
398                     'type'      => 'image_width',
399                     'default'   => array(
400                         'width'     => '90',
401                         'height'    => '90',
402                         'crop'      => 1
403                     ),
404                     'desc_tip'  =>  true,
405                 ),
406 
407                 array( 'type' => 'sectionend', 'id' => 'image_options' ),
408 
409                 array(  'title' => __( 'Downloadable Products', 'woocommerce' ), 'type' => 'title', 'id' => 'digital_download_options' ),
410 
411                 array(
412                     'title' => __( 'File Download Method', 'woocommerce' ),
413                     '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' ),
414                     'id'        => 'woocommerce_file_download_method',
415                     'type'      => 'select',
416                     'class'     => 'chosen_select',
417                     'css'       => 'min-width:300px;',
418                     'default'   => 'force',
419                     'desc_tip'  =>  true,
420                     'options' => array(
421                         'force'     => __( 'Force Downloads', 'woocommerce' ),
422                         'xsendfile' => __( 'X-Accel-Redirect/X-Sendfile', 'woocommerce' ),
423                         'redirect'  => __( 'Redirect only', 'woocommerce' ),
424                     ),
425                     'autoload'      => false
426                 ),
427 
428                 array(
429                     'title' => __( 'Access Restriction', 'woocommerce' ),
430                     'desc'      => __( 'Downloads require login', 'woocommerce' ),
431                     'id'        => 'woocommerce_downloads_require_login',
432                     'type'      => 'checkbox',
433                     'default'   => 'no',
434                     'desc_tip'  => __( 'This setting does not apply to guest purchases.', 'woocommerce' ),
435                     'checkboxgroup'     => 'start',
436                     'autoload'      => false
437                 ),
438 
439                 array(
440                     'desc'      => __( 'Grant access to downloadable products after payment', 'woocommerce' ),
441                     'id'        => 'woocommerce_downloads_grant_access_after_payment',
442                     'type'      => 'checkbox',
443                     'default'   => 'yes',
444                     'desc_tip'  => __( 'Enable this option to grant access to downloads when orders are "processing", rather than "completed".', 'woocommerce' ),
445                     'checkboxgroup'     => 'end',
446                     'autoload'      => false
447                 ),
448 
449                 array( 'type' => 'sectionend', 'id' => 'digital_download_options' ),
450 
451             ));
452         }
453     }
454 }
455 
456 endif;
457 
458 return new WC_Settings_Products();
WooCommerce API documentation generated by ApiGen 2.8.0