woocommerce/includes/admin/settings/class-wc-settings-products.php

563 lines
19 KiB
PHP
Raw Normal View History

<?php
/**
2015-11-03 13:53:50 +00:00
* WooCommerce Product Settings
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin
* @version 2.4.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( class_exists( 'WC_Settings_Products', false ) ) {
return new WC_Settings_Products();
}
/**
2015-11-03 13:31:20 +00:00
* WC_Settings_Products.
*/
class WC_Settings_Products extends WC_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'products';
$this->label = __( 'Products', 'woocommerce' );
parent::__construct();
}
/**
2015-11-03 13:31:20 +00:00
* Get sections.
*
* @return array
*/
public function get_sections() {
$sections = array(
2014-11-11 14:25:46 +00:00
'' => __( 'General', 'woocommerce' ),
'display' => __( 'Display', 'woocommerce' ),
2014-10-31 19:07:00 +00:00
'inventory' => __( 'Inventory', 'woocommerce' ),
'downloadable' => __( 'Downloadable products', 'woocommerce' ),
);
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
}
/**
2015-11-03 13:31:20 +00:00
* Output the settings.
*/
public function output() {
global $current_section;
$settings = $this->get_settings( $current_section );
2015-05-15 19:35:50 +00:00
WC_Admin_Settings::output_fields( $settings );
}
/**
2015-11-03 13:31:20 +00:00
* Save settings.
*/
public function save() {
global $current_section;
$settings = $this->get_settings( $current_section );
WC_Admin_Settings::save_fields( $settings );
}
/**
2015-11-03 13:31:20 +00:00
* Get settings array.
*
* @param string $current_section Current section name.
* @return array
*/
public function get_settings( $current_section = '' ) {
if ( 'display' === $current_section ) {
$theme_support = get_theme_support( 'woocommerce' );
$theme_support = is_array( $theme_support ) ? $theme_support[0]: false;
$settings = array(
2014-11-11 14:40:13 +00:00
array(
'title' => __( 'Shop &amp; product pages', 'woocommerce' ),
2014-11-11 14:40:13 +00:00
'type' => 'title',
'desc' => '',
'id' => 'catalog_options',
2014-11-11 14:40:13 +00:00
),
2014-11-11 14:29:54 +00:00
array(
'title' => __( 'Shop page', 'woocommerce' ),
2014-11-11 14:29:54 +00:00
'desc' => '<br/>' . sprintf( __( 'The base page can also be used in your <a href="%s">product permalinks</a>.', 'woocommerce' ), admin_url( 'options-permalink.php' ) ),
'id' => 'woocommerce_shop_page_id',
'type' => 'single_select_page',
'default' => '',
2015-01-12 16:29:01 +00:00
'class' => 'wc-enhanced-select-nostd',
2014-11-11 14:29:54 +00:00
'css' => 'min-width:300px;',
'desc_tip' => __( 'This sets the base page of your shop - this is where your product archive will be.', 'woocommerce' ),
),
array(
'title' => __( 'Shop page display', 'woocommerce' ),
2014-11-11 14:29:54 +00:00
'desc' => __( 'This controls what is shown on the product archive.', 'woocommerce' ),
'id' => 'woocommerce_shop_page_display',
2015-01-12 16:29:01 +00:00
'class' => 'wc-enhanced-select',
2014-11-11 14:29:54 +00:00
'css' => 'min-width:300px;',
'default' => '',
'type' => 'select',
'options' => array(
'' => __( 'Show products', 'woocommerce' ),
'subcategories' => __( 'Show categories', 'woocommerce' ),
'both' => __( 'Show categories &amp; products', 'woocommerce' ),
2014-11-11 14:29:54 +00:00
),
'desc_tip' => true,
2014-11-11 14:29:54 +00:00
),
array(
'title' => __( 'Default category display', 'woocommerce' ),
2014-11-11 14:29:54 +00:00
'desc' => __( 'This controls what is shown on category archives.', 'woocommerce' ),
'id' => 'woocommerce_category_archive_display',
2015-01-12 16:29:01 +00:00
'class' => 'wc-enhanced-select',
2014-11-11 14:29:54 +00:00
'css' => 'min-width:300px;',
'default' => '',
'type' => 'select',
'options' => array(
'' => __( 'Show products', 'woocommerce' ),
'subcategories' => __( 'Show subcategories', 'woocommerce' ),
'both' => __( 'Show subcategories &amp; products', 'woocommerce' ),
2014-11-11 14:29:54 +00:00
),
'desc_tip' => true,
2014-11-11 14:29:54 +00:00
),
array(
'title' => __( 'Default product sorting', 'woocommerce' ),
2014-11-11 14:29:54 +00:00
'desc' => __( 'This controls the default sort order of the catalog.', 'woocommerce' ),
'id' => 'woocommerce_default_catalog_orderby',
2015-01-12 16:29:01 +00:00
'class' => 'wc-enhanced-select',
2014-11-11 14:29:54 +00:00
'css' => 'min-width:300px;',
'default' => 'menu_order',
2014-11-11 14:29:54 +00:00
'type' => 'select',
2014-11-11 14:54:32 +00:00
'options' => apply_filters( 'woocommerce_default_catalog_orderby_options', array(
2014-11-11 14:29:54 +00:00
'menu_order' => __( 'Default sorting (custom ordering + name)', 'woocommerce' ),
'popularity' => __( 'Popularity (sales)', 'woocommerce' ),
'rating' => __( 'Average rating', 'woocommerce' ),
2014-11-11 14:29:54 +00:00
'date' => __( 'Sort by most recent', 'woocommerce' ),
'price' => __( 'Sort by price (asc)', 'woocommerce' ),
'price-desc' => __( 'Sort by price (desc)', 'woocommerce' ),
2014-11-11 14:54:32 +00:00
) ),
'desc_tip' => true,
2014-11-11 14:29:54 +00:00
),
'columns' => array(
2017-11-09 12:37:14 +00:00
'title' => __( 'Products per row', 'woocommerce' ),
'desc' => __( 'How many products should be shown per row?', 'woocommerce' ),
'id' => 'woocommerce_catalog_columns',
'default' => '3',
'type' => 'number',
'css' => 'width: 50px;',
'custom_attributes' => array(
'min' => isset( $theme_support['product_grid']['min_columns'] ) ? absint( $theme_support['product_grid']['min_columns'] ) : 1,
'max' => isset( $theme_support['product_grid']['max_columns'] ) ? absint( $theme_support['product_grid']['max_columns'] ) : '',
'step' => 1,
2017-11-09 12:37:14 +00:00
),
'desc_tip' => true,
),
'rows' => array(
2017-11-09 12:37:14 +00:00
'title' => __( 'Rows per page', 'woocommerce' ),
'desc' => __( 'How many rows of products should be shown per page?', 'woocommerce' ),
'id' => 'woocommerce_catalog_rows',
'default' => '4',
'type' => 'number',
'css' => 'width: 50px;',
'custom_attributes' => array(
'min' => isset( $theme_support['product_grid']['min_rows'] ) ? absint( $theme_support['product_grid']['min_rows'] ): 1,
'max' => isset( $theme_support['product_grid']['max_rows'] ) ? absint( $theme_support['product_grid']['max_rows'] ): '',
'step' => 1,
2017-11-09 12:37:14 +00:00
),
'desc_tip' => true,
),
2014-11-11 14:29:54 +00:00
array(
'title' => __( 'Add to cart behaviour', 'woocommerce' ),
'desc' => __( 'Redirect to the cart page after successful addition', 'woocommerce' ),
'id' => 'woocommerce_cart_redirect_after_add',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'start',
2014-11-11 14:29:54 +00:00
),
array(
'desc' => __( 'Enable AJAX add to cart buttons on archives', 'woocommerce' ),
'id' => 'woocommerce_enable_ajax_add_to_cart',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
2014-11-11 14:29:54 +00:00
),
2014-11-11 14:40:13 +00:00
array(
'type' => 'sectionend',
'id' => 'catalog_options',
2014-11-11 14:40:13 +00:00
),
);
2014-11-11 14:29:54 +00:00
if ( has_filter( 'loop_shop_columns' ) ) {
unset( $settings['columns'], $settings['rows'] );
}
2017-11-07 18:32:43 +00:00
$image_settings = array(
2014-11-11 14:40:13 +00:00
array(
'title' => __( 'Product images', 'woocommerce' ),
2014-11-11 14:40:13 +00:00
'type' => 'title',
2017-11-07 18:32:43 +00:00
'desc' => __( 'These settings change how product images are displayed in your catalog.', 'woocommerce' ),
'id' => 'image_options',
2014-11-11 14:40:13 +00:00
),
2017-11-07 18:32:43 +00:00
'single_image_width' => array(
'title' => __( 'Main image width', 'woocommerce' ),
'desc' => __( 'This is the width used by the main image on single product pages. These images will be uncropped.', 'woocommerce' ),
'id' => 'woocommerce_single_image_width',
2014-11-11 14:29:54 +00:00
'css' => '',
2017-11-07 19:08:06 +00:00
'type' => 'text',
'custom_attributes' => array(
'size' => 3,
2014-11-11 14:29:54 +00:00
),
2017-11-07 19:08:06 +00:00
'suffix' => 'px',
2017-11-07 18:32:43 +00:00
'default' => 600,
'desc_tip' => true,
2014-11-11 14:29:54 +00:00
),
2017-11-07 18:32:43 +00:00
'thumbnail_image_width' => array(
'title' => __( 'Thumbnail width', 'woocommerce' ),
'desc' => __( 'This size is used for product archives and product listings.', 'woocommerce' ),
'id' => 'woocommerce_thumbnail_image_width',
2014-11-11 14:29:54 +00:00
'css' => '',
2017-11-07 19:08:06 +00:00
'type' => 'text',
'custom_attributes' => array(
'size' => 3,
2014-11-11 14:29:54 +00:00
),
2017-11-07 19:08:06 +00:00
'suffix' => 'px',
2017-11-07 18:32:43 +00:00
'default' => 300,
'desc_tip' => true,
2014-11-11 14:29:54 +00:00
),
array(
2017-11-07 18:32:43 +00:00
'title' => __( 'Thumbnail cropping', 'woocommerce' ),
'desc' => __( 'This determines how thumbnails appear. Widths will be fixed, whilst heights may vary.', 'woocommerce' ),
'id' => 'woocommerce_thumbnail_cropping',
2014-11-11 14:29:54 +00:00
'css' => '',
2017-11-07 18:32:43 +00:00
'type' => 'thumbnail_cropping',
'default' => '1:1',
'desc_tip' => false,
2014-11-11 14:29:54 +00:00
),
2014-11-11 14:40:13 +00:00
array(
'type' => 'sectionend',
'id' => 'image_options',
),
2017-11-07 18:32:43 +00:00
);
2014-11-11 14:29:54 +00:00
2017-11-07 18:32:43 +00:00
if ( isset( $theme_support['single_image_width'] ) ) {
unset( $image_settings['single_image_width'] );
}
if ( isset( $theme_support['thumbnail_image_width'] ) ) {
unset( $image_settings['thumbnail_image_width'] );
}
2014-11-11 14:29:54 +00:00
$settings = apply_filters( 'woocommerce_product_settings', array_merge( $settings, $image_settings ) );
} elseif ( 'inventory' === $current_section ) {
$settings = apply_filters( 'woocommerce_inventory_settings', array(
2014-11-11 14:40:13 +00:00
array(
'title' => __( 'Inventory', 'woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'product_inventory_options',
2014-11-11 14:40:13 +00:00
),
array(
'title' => __( 'Manage stock', 'woocommerce' ),
'desc' => __( 'Enable stock management', 'woocommerce' ),
'id' => 'woocommerce_manage_stock',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Hold stock (minutes)', 'woocommerce' ),
'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' ),
'id' => 'woocommerce_hold_stock_minutes',
'type' => 'number',
'custom_attributes' => array(
'min' => 0,
'step' => 1,
),
'css' => 'width: 80px;',
'default' => '60',
'autoload' => false,
'class' => 'manage_stock_field',
),
array(
'title' => __( 'Notifications', 'woocommerce' ),
'desc' => __( 'Enable low stock notifications', 'woocommerce' ),
'id' => 'woocommerce_notify_low_stock',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false,
'class' => 'manage_stock_field',
),
array(
'desc' => __( 'Enable out of stock notifications', 'woocommerce' ),
'id' => 'woocommerce_notify_no_stock',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false,
'class' => 'manage_stock_field',
),
array(
'title' => __( 'Notification recipient(s)', 'woocommerce' ),
'desc' => __( 'Enter recipients (comma separated) that will receive this notification.', 'woocommerce' ),
'id' => 'woocommerce_stock_email_recipient',
'type' => 'text',
'default' => get_option( 'admin_email' ),
'css' => 'width: 250px;',
'autoload' => false,
'desc_tip' => true,
'class' => 'manage_stock_field',
),
array(
'title' => __( 'Low stock threshold', 'woocommerce' ),
2016-07-01 11:06:31 +00:00
'desc' => __( 'When product stock reaches this amount you will be notified via email.', 'woocommerce' ),
'id' => 'woocommerce_notify_low_stock_amount',
'css' => 'width:50px;',
'type' => 'number',
'custom_attributes' => array(
'min' => 0,
'step' => 1,
),
'default' => '2',
2016-07-01 11:06:31 +00:00
'autoload' => false,
'desc_tip' => true,
'class' => 'manage_stock_field',
),
array(
'title' => __( 'Out of stock threshold', 'woocommerce' ),
2016-07-01 11:06:31 +00:00
'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' ),
'id' => 'woocommerce_notify_no_stock_amount',
'css' => 'width:50px;',
'type' => 'number',
'custom_attributes' => array(
'min' => 0,
'step' => 1,
),
2016-07-01 11:06:31 +00:00
'default' => '0',
'desc_tip' => true,
'class' => 'manage_stock_field',
),
array(
'title' => __( 'Out of stock visibility', 'woocommerce' ),
'desc' => __( 'Hide out of stock items from the catalog', 'woocommerce' ),
'id' => 'woocommerce_hide_out_of_stock_items',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Stock display format', 'woocommerce' ),
2017-03-20 16:08:53 +00:00
'desc' => __( 'This controls how stock quantities are displayed on the frontend.', 'woocommerce' ),
'id' => 'woocommerce_stock_format',
'css' => 'min-width:150px;',
2015-01-12 17:45:47 +00:00
'class' => 'wc-enhanced-select',
'default' => '',
'type' => 'select',
'options' => array(
2017-03-20 16:08:53 +00:00
'' => __( 'Always show quantity remaining in stock e.g. "12 in stock"', 'woocommerce' ),
'low_amount' => __( 'Only show quantity remaining in stock when low e.g. "Only 2 left in stock"', 'woocommerce' ),
'no_amount' => __( 'Never show quantity remaining in stock', 'woocommerce' ),
),
'desc_tip' => true,
),
2014-11-11 14:40:13 +00:00
array(
'type' => 'sectionend',
'id' => 'product_inventory_options',
2014-11-11 14:40:13 +00:00
),
));
} elseif ( 'downloadable' === $current_section ) {
2014-10-31 19:07:00 +00:00
$settings = apply_filters( 'woocommerce_downloadable_products_settings', array(
2014-11-11 14:40:13 +00:00
array(
'title' => __( 'Downloadable products', 'woocommerce' ),
2014-11-11 14:40:13 +00:00
'type' => 'title',
'id' => 'digital_download_options',
2014-11-11 14:40:13 +00:00
),
2014-10-31 19:07:00 +00:00
array(
'title' => __( 'File download method', 'woocommerce' ),
'desc' => sprintf(
/* translators: 1: X-Accel-Redirect 2: X-Sendfile 3: mod_xsendfile */
__( 'Forcing downloads will keep URLs hidden, but some servers may serve large files unreliably. If supported, %1$s / %2$s can be used to serve downloads instead (server requires %3$s).', 'woocommerce' ),
'<code>X-Accel-Redirect</code>',
'<code>X-Sendfile</code>',
'<code>mod_xsendfile</code>'
),
2014-10-31 19:07:00 +00:00
'id' => 'woocommerce_file_download_method',
'type' => 'select',
2015-01-12 16:29:01 +00:00
'class' => 'wc-enhanced-select',
2014-10-31 19:07:00 +00:00
'css' => 'min-width:300px;',
'default' => 'force',
'desc_tip' => true,
2014-10-31 19:07:00 +00:00
'options' => array(
'force' => __( 'Force downloads', 'woocommerce' ),
2014-10-31 19:07:00 +00:00
'xsendfile' => __( 'X-Accel-Redirect/X-Sendfile', 'woocommerce' ),
'redirect' => __( 'Redirect only', 'woocommerce' ),
),
'autoload' => false,
2014-10-31 19:07:00 +00:00
),
array(
'title' => __( 'Access restriction', 'woocommerce' ),
2014-10-31 19:07:00 +00:00
'desc' => __( 'Downloads require login', 'woocommerce' ),
'id' => 'woocommerce_downloads_require_login',
'type' => 'checkbox',
'default' => 'no',
'desc_tip' => __( 'This setting does not apply to guest purchases.', 'woocommerce' ),
'checkboxgroup' => 'start',
'autoload' => false,
2014-10-31 19:07:00 +00:00
),
array(
'desc' => __( 'Grant access to downloadable products after payment', 'woocommerce' ),
'id' => 'woocommerce_downloads_grant_access_after_payment',
'type' => 'checkbox',
'default' => 'yes',
'desc_tip' => __( 'Enable this option to grant access to downloads when orders are "processing", rather than "completed".', 'woocommerce' ),
'checkboxgroup' => 'end',
'autoload' => false,
2014-10-31 19:07:00 +00:00
),
2014-11-11 14:40:13 +00:00
array(
'type' => 'sectionend',
'id' => 'digital_download_options',
2014-11-11 14:40:13 +00:00
),
2014-10-31 19:07:00 +00:00
));
2014-11-11 14:25:46 +00:00
} else {
$settings = apply_filters( 'woocommerce_products_general_settings', array(
2014-11-11 14:40:13 +00:00
array(
'title' => __( 'Measurements', 'woocommerce' ),
'type' => 'title',
'id' => 'product_measurement_options',
2014-11-11 14:40:13 +00:00
),
2014-11-11 14:25:46 +00:00
array(
'title' => __( 'Weight unit', 'woocommerce' ),
2014-11-11 14:25:46 +00:00
'desc' => __( 'This controls what unit you will define weights in.', 'woocommerce' ),
'id' => 'woocommerce_weight_unit',
2015-01-12 16:29:01 +00:00
'class' => 'wc-enhanced-select',
2014-11-11 14:25:46 +00:00
'css' => 'min-width:300px;',
'default' => 'kg',
'type' => 'select',
'options' => array(
'kg' => __( 'kg', 'woocommerce' ),
'g' => __( 'g', 'woocommerce' ),
'lbs' => __( 'lbs', 'woocommerce' ),
'oz' => __( 'oz', 'woocommerce' ),
),
'desc_tip' => true,
2014-11-11 14:25:46 +00:00
),
array(
'title' => __( 'Dimensions unit', 'woocommerce' ),
2014-11-11 14:25:46 +00:00
'desc' => __( 'This controls what unit you will define lengths in.', 'woocommerce' ),
'id' => 'woocommerce_dimension_unit',
2015-01-12 16:29:01 +00:00
'class' => 'wc-enhanced-select',
2014-11-11 14:25:46 +00:00
'css' => 'min-width:300px;',
'default' => 'cm',
'type' => 'select',
'options' => array(
'm' => __( 'm', 'woocommerce' ),
'cm' => __( 'cm', 'woocommerce' ),
'mm' => __( 'mm', 'woocommerce' ),
'in' => __( 'in', 'woocommerce' ),
'yd' => __( 'yd', 'woocommerce' ),
),
'desc_tip' => true,
2014-11-11 14:25:46 +00:00
),
2014-11-11 14:40:13 +00:00
array(
'type' => 'sectionend',
2016-02-11 11:13:48 +00:00
'id' => 'product_measurement_options',
2014-11-11 14:40:13 +00:00
),
2014-11-11 14:25:46 +00:00
2014-11-11 14:40:13 +00:00
array(
'title' => __( 'Reviews', 'woocommerce' ),
'type' => 'title',
'desc' => '',
2016-02-11 11:13:48 +00:00
'id' => 'product_rating_options',
2014-11-11 14:40:13 +00:00
),
2014-11-11 14:25:46 +00:00
array(
2017-06-08 14:26:30 +00:00
'title' => __( 'Enable reviews', 'woocommerce' ),
'desc' => __( 'Enable product reviews', 'woocommerce' ),
'id' => 'woocommerce_enable_reviews',
2014-11-11 14:25:46 +00:00
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
2016-02-11 11:13:48 +00:00
'show_if_checked' => 'option',
2014-11-11 14:25:46 +00:00
),
array(
2017-06-08 14:26:30 +00:00
'desc' => __( 'Show "verified owner" label on customer reviews', 'woocommerce' ),
'id' => 'woocommerce_review_rating_verification_label',
2014-11-11 14:25:46 +00:00
'default' => 'yes',
'type' => 'checkbox',
2017-06-08 14:26:30 +00:00
'checkboxgroup' => '',
'show_if_checked' => 'yes',
'autoload' => false,
),
array(
'desc' => __( 'Reviews can only be left by "verified owners"', 'woocommerce' ),
'id' => 'woocommerce_review_rating_verification_required',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
2014-11-11 14:25:46 +00:00
'show_if_checked' => 'yes',
2016-02-11 11:13:48 +00:00
'autoload' => false,
2014-11-11 14:25:46 +00:00
),
array(
2017-06-08 14:26:30 +00:00
'title' => __( 'Product ratings', 'woocommerce' ),
'desc' => __( 'Enable star rating on reviews', 'woocommerce' ),
'id' => 'woocommerce_enable_review_rating',
2014-11-11 14:25:46 +00:00
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
2017-06-08 14:26:30 +00:00
'show_if_checked' => 'option',
2014-11-11 14:25:46 +00:00
),
array(
2017-06-08 14:26:30 +00:00
'desc' => __( 'Star ratings should be required, not optional', 'woocommerce' ),
'id' => 'woocommerce_review_rating_required',
'default' => 'yes',
2014-11-11 14:25:46 +00:00
'type' => 'checkbox',
'checkboxgroup' => 'end',
'show_if_checked' => 'yes',
2016-02-11 11:13:48 +00:00
'autoload' => false,
2014-11-11 14:25:46 +00:00
),
2014-11-11 14:40:13 +00:00
array(
'type' => 'sectionend',
'id' => 'product_rating_options',
2014-11-11 14:40:13 +00:00
),
2014-11-11 14:25:46 +00:00
));
}
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
}
}
return new WC_Settings_Products();