2013-08-22 10:58:03 +00:00
< ? php
/**
2015-11-03 13:53:50 +00:00
* WooCommerce Product Settings
2013-08-22 10:58:03 +00:00
*
2020-08-05 16:36:24 +00:00
* @ package WooCommerce\Admin
2018-06-27 17:38:36 +00:00
* @ version 2.4 . 0
2013-08-22 10:58:03 +00:00
*/
2014-09-20 19:55:47 +00:00
if ( ! defined ( 'ABSPATH' ) ) {
2017-11-07 11:04:15 +00:00
exit ;
2014-09-20 19:55:47 +00:00
}
2013-08-22 10:58:03 +00:00
2017-11-07 11:04:15 +00:00
if ( class_exists ( 'WC_Settings_Products' , false ) ) {
return new WC_Settings_Products ();
}
2013-08-22 10:58:03 +00:00
/**
2015-11-03 13:31:20 +00:00
* WC_Settings_Products .
2013-08-22 10:58:03 +00:00
*/
class WC_Settings_Products extends WC_Settings_Page {
/**
* Constructor .
*/
public function __construct () {
$this -> id = 'products' ;
$this -> label = __ ( 'Products' , 'woocommerce' );
2017-08-12 00:36:35 +00:00
parent :: __construct ();
2013-08-22 10:58:03 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Get sections .
2013-08-22 10:58:03 +00:00
*
* @ return array
*/
public function get_sections () {
$sections = array (
2018-03-05 18:59:17 +00:00
'' => __ ( 'General' , 'woocommerce' ),
'inventory' => __ ( 'Inventory' , 'woocommerce' ),
'downloadable' => __ ( 'Downloadable products' , 'woocommerce' ),
2013-08-22 10:58:03 +00:00
);
2014-02-17 14:30:37 +00:00
return apply_filters ( 'woocommerce_get_sections_' . $this -> id , $sections );
2013-08-22 10:58:03 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Output the settings .
2013-08-22 10:58:03 +00:00
*/
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 );
2013-08-22 10:58:03 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Save settings .
2013-08-22 10:58:03 +00:00
*/
public function save () {
global $current_section ;
$settings = $this -> get_settings ( $current_section );
WC_Admin_Settings :: save_fields ( $settings );
2018-01-26 09:22:09 +00:00
2021-01-28 16:26:24 +00:00
// Any time we update the product settings, we should flush the term count cache.
$tools_controller = new WC_REST_System_Status_Tools_Controller ();
$tools_controller -> execute_tool ( 'recount_terms' );
2018-01-26 09:22:09 +00:00
if ( $current_section ) {
do_action ( 'woocommerce_update_options_' . $this -> id . '_' . $current_section );
}
2013-08-22 10:58:03 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Get settings array .
2013-08-22 10:58:03 +00:00
*
2017-11-07 11:04:15 +00:00
* @ param string $current_section Current section name .
2013-08-22 10:58:03 +00:00
* @ return array
*/
public function get_settings ( $current_section = '' ) {
2017-11-14 16:36:18 +00:00
if ( 'inventory' === $current_section ) {
2018-03-05 18:59:17 +00:00
$settings = apply_filters (
2019-04-10 12:29:40 +00:00
'woocommerce_inventory_settings' ,
array (
2018-03-05 18:59:17 +00:00
array (
'title' => __ ( 'Inventory' , 'woocommerce' ),
'type' => 'title' ,
'desc' => '' ,
'id' => 'product_inventory_options' ,
2013-08-22 10:58:03 +00:00
),
2018-03-05 18:59:17 +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' ),
'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' ,
'autoload' => false ,
'desc_tip' => true ,
'class' => 'manage_stock_field' ,
),
array (
'title' => __ ( 'Out of stock threshold' , 'woocommerce' ),
'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 ,
),
'default' => '0' ,
'desc_tip' => true ,
'class' => 'manage_stock_field' ,
2013-08-22 10:58:03 +00:00
),
2018-03-05 18:59:17 +00:00
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' ,
2013-08-22 10:58:03 +00:00
),
2018-03-05 18:59:17 +00:00
array (
'title' => __ ( 'Stock display format' , 'woocommerce' ),
'desc' => __ ( 'This controls how stock quantities are displayed on the frontend.' , 'woocommerce' ),
'id' => 'woocommerce_stock_format' ,
'css' => 'min-width:150px;' ,
'class' => 'wc-enhanced-select' ,
'default' => '' ,
'type' => 'select' ,
'options' => array (
'' => __ ( '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 ,
2013-08-22 10:58:03 +00:00
),
2018-03-05 18:59:17 +00:00
array (
'type' => 'sectionend' ,
'id' => 'product_inventory_options' ,
),
2013-08-22 10:58:03 +00:00
2018-03-05 18:59:17 +00:00
)
);
2013-08-22 10:58:03 +00:00
2017-11-07 11:04:15 +00:00
} elseif ( 'downloadable' === $current_section ) {
2018-03-05 18:59:17 +00:00
$settings = apply_filters (
2019-04-10 12:29:40 +00:00
'woocommerce_downloadable_products_settings' ,
array (
2018-03-05 18:59:17 +00:00
array (
'title' => __ ( 'Downloadable products' , 'woocommerce' ),
'type' => 'title' ,
'id' => 'digital_download_options' ,
2017-08-23 13:22:52 +00:00
),
2018-03-05 18:59:17 +00:00
array (
'title' => __ ( 'File download method' , 'woocommerce' ),
2020-03-08 20:06:37 +00:00
'desc_tip' => sprintf (
2018-03-05 18:59:17 +00:00
/* 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>'
),
'id' => 'woocommerce_file_download_method' ,
'type' => 'select' ,
'class' => 'wc-enhanced-select' ,
'css' => 'min-width:300px;' ,
'default' => 'force' ,
2020-03-08 20:06:37 +00:00
'desc' => sprintf (
// translators: Link to WooCommerce Docs.
__ ( " If you are using X-Accel-Redirect download method along with NGINX server, make sure that you have applied settings as described in <a href='%s'>Digital/Downloadable Product Handling</a> guide. " , 'woocommerce' ),
'https://docs.woocommerce.com/document/digital-downloadable-product-handling#nginx-setting'
),
2018-03-05 18:59:17 +00:00
'options' => array (
'force' => __ ( 'Force downloads' , 'woocommerce' ),
'xsendfile' => __ ( 'X-Accel-Redirect/X-Sendfile' , 'woocommerce' ),
2020-02-06 08:41:22 +00:00
'redirect' => apply_filters ( 'woocommerce_redirect_only_method_is_secure' , false ) ? __ ( 'Redirect only' , 'woocommerce' ) : __ ( 'Redirect only (Insecure)' , 'woocommerce' ),
2018-03-05 18:59:17 +00:00
),
'autoload' => false ,
2014-10-31 19:07:00 +00:00
),
2018-03-05 18:59:17 +00:00
array (
'title' => __ ( 'Access restriction' , 'woocommerce' ),
'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-11-11 14:25:46 +00:00
),
2018-03-05 18:59:17 +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 ,
),
2020-01-17 14:04:16 +00:00
array (
'title' => __ ( 'Filename' , 'woocommerce' ),
'desc' => __ ( 'Append a unique string to filename for security' , 'woocommerce' ),
'id' => 'woocommerce_downloads_add_hash_to_filename' ,
'type' => 'checkbox' ,
'default' => 'yes' ,
'desc_tip' => sprintf (
// translators: Link to WooCommerce Docs.
2020-03-12 11:33:03 +00:00
__ ( " Not required if your download directory is protected. <a href='%s'>See this guide</a> for more details. Files already uploaded will not be affected. " , 'woocommerce' ),
2020-03-08 20:06:37 +00:00
'https://docs.woocommerce.com/document/digital-downloadable-product-handling#unique-string'
2020-01-17 14:04:16 +00:00
),
),
2018-03-05 18:59:17 +00:00
array (
'type' => 'sectionend' ,
'id' => 'digital_download_options' ,
2014-11-11 14:25:46 +00:00
),
2018-03-05 18:59:17 +00:00
)
);
} else {
$settings = apply_filters (
2019-04-10 12:29:40 +00:00
'woocommerce_product_settings' ,
apply_filters (
'woocommerce_products_general_settings' ,
array (
2018-03-05 18:59:17 +00:00
array (
'title' => __ ( 'Shop pages' , 'woocommerce' ),
'type' => 'title' ,
'desc' => '' ,
'id' => 'catalog_options' ,
),
array (
'title' => __ ( 'Shop page' , 'woocommerce' ),
2018-06-27 17:38:36 +00:00
/* translators: %s: URL to settings. */
2019-04-09 14:02:05 +00:00
'desc' => sprintf ( __ ( 'The base page can also be used in your <a href="%s">product permalinks</a>.' , 'woocommerce' ), admin_url ( 'options-permalink.php' ) ),
2018-03-05 18:59:17 +00:00
'id' => 'woocommerce_shop_page_id' ,
'type' => 'single_select_page' ,
'default' => '' ,
2020-10-06 15:11:58 +00:00
'args' => array ( 'post_status' => 'publish,private' ),
2018-03-05 18:59:17 +00:00
'class' => 'wc-enhanced-select-nostd' ,
'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' => __ ( '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' ,
),
array (
'desc' => __ ( 'Enable AJAX add to cart buttons on archives' , 'woocommerce' ),
'id' => 'woocommerce_enable_ajax_add_to_cart' ,
'default' => 'yes' ,
'type' => 'checkbox' ,
'checkboxgroup' => 'end' ,
),
2018-06-27 17:38:36 +00:00
array (
'title' => __ ( 'Placeholder image' , 'woocommerce' ),
'id' => 'woocommerce_placeholder_image' ,
'type' => 'text' ,
'default' => '' ,
'class' => '' ,
'css' => '' ,
'placeholder' => __ ( 'Enter attachment ID or URL to an image' , 'woocommerce' ),
'desc_tip' => __ ( 'This is the attachment ID, or image URL, used for placeholder images in the product catalog. Products with no image will use this.' , 'woocommerce' ),
),
2018-03-05 18:59:17 +00:00
array (
'type' => 'sectionend' ,
'id' => 'catalog_options' ,
),
array (
'title' => __ ( 'Measurements' , 'woocommerce' ),
'type' => 'title' ,
'id' => 'product_measurement_options' ,
),
array (
'title' => __ ( 'Weight unit' , 'woocommerce' ),
'desc' => __ ( 'This controls what unit you will define weights in.' , 'woocommerce' ),
'id' => 'woocommerce_weight_unit' ,
'class' => 'wc-enhanced-select' ,
'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 ,
),
array (
'title' => __ ( 'Dimensions unit' , 'woocommerce' ),
'desc' => __ ( 'This controls what unit you will define lengths in.' , 'woocommerce' ),
'id' => 'woocommerce_dimension_unit' ,
'class' => 'wc-enhanced-select' ,
'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 ,
),
array (
'type' => 'sectionend' ,
'id' => 'product_measurement_options' ,
),
array (
'title' => __ ( 'Reviews' , 'woocommerce' ),
'type' => 'title' ,
'desc' => '' ,
'id' => 'product_rating_options' ,
),
array (
'title' => __ ( 'Enable reviews' , 'woocommerce' ),
'desc' => __ ( 'Enable product reviews' , 'woocommerce' ),
'id' => 'woocommerce_enable_reviews' ,
'default' => 'yes' ,
'type' => 'checkbox' ,
'checkboxgroup' => 'start' ,
'show_if_checked' => 'option' ,
),
array (
'desc' => __ ( 'Show "verified owner" label on customer reviews' , 'woocommerce' ),
'id' => 'woocommerce_review_rating_verification_label' ,
'default' => 'yes' ,
'type' => 'checkbox' ,
'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' ,
'show_if_checked' => 'yes' ,
'autoload' => false ,
),
array (
'title' => __ ( 'Product ratings' , 'woocommerce' ),
'desc' => __ ( 'Enable star rating on reviews' , 'woocommerce' ),
'id' => 'woocommerce_enable_review_rating' ,
'default' => 'yes' ,
'type' => 'checkbox' ,
'checkboxgroup' => 'start' ,
'show_if_checked' => 'option' ,
),
array (
'desc' => __ ( 'Star ratings should be required, not optional' , 'woocommerce' ),
'id' => 'woocommerce_review_rating_required' ,
'default' => 'yes' ,
'type' => 'checkbox' ,
'checkboxgroup' => 'end' ,
'show_if_checked' => 'yes' ,
'autoload' => false ,
),
array (
'type' => 'sectionend' ,
'id' => 'product_rating_options' ,
),
)
)
);
2013-08-22 10:58:03 +00:00
}
2014-09-12 11:20:06 +00:00
return apply_filters ( 'woocommerce_get_settings_' . $this -> id , $settings , $current_section );
2013-08-22 10:58:03 +00:00
}
}
2014-08-31 08:22:03 +00:00
return new WC_Settings_Products ();