2013-07-26 14:36:28 +00:00
< ? php
/**
* WooCommerce General Settings
*
2014-08-31 08:22:03 +00:00
* @ author WooThemes
* @ category Admin
* @ package WooCommerce / Admin
2013-07-26 14:36:28 +00:00
* @ version 2.1 . 0
*/
2014-04-08 22:11:33 +00:00
if ( ! defined ( 'ABSPATH' ) ) {
exit ; // Exit if accessed directly
}
2013-07-26 14:36:28 +00:00
if ( ! class_exists ( 'WC_Settings_General' ) ) :
/**
* WC_Admin_Settings_General
*/
class WC_Settings_General extends WC_Settings_Page {
/**
* Constructor .
*/
public function __construct () {
2014-08-31 08:22:03 +00:00
2013-07-26 14:36:28 +00:00
$this -> id = 'general' ;
$this -> label = __ ( 'General' , 'woocommerce' );
add_filter ( 'woocommerce_settings_tabs_array' , array ( $this , 'add_settings_page' ), 20 );
add_action ( 'woocommerce_settings_' . $this -> id , array ( $this , 'output' ) );
add_action ( 'woocommerce_settings_save_' . $this -> id , array ( $this , 'save' ) );
2013-08-02 11:27:31 +00:00
2014-04-08 22:11:33 +00:00
if ( ( $styles = WC_Frontend_Scripts :: get_styles () ) && array_key_exists ( 'woocommerce-general' , $styles ) ) {
2013-08-02 11:27:31 +00:00
add_action ( 'woocommerce_admin_field_frontend_styles' , array ( $this , 'frontend_styles_setting' ) );
2014-04-08 22:11:33 +00:00
}
2013-07-26 14:36:28 +00:00
}
/**
* Get settings array
*
* @ return array
*/
public function get_settings () {
2014-08-31 08:22:03 +00:00
2013-07-26 14:36:28 +00:00
$currency_code_options = get_woocommerce_currencies ();
2014-04-08 22:11:33 +00:00
foreach ( $currency_code_options as $code => $name ) {
2013-07-26 14:36:28 +00:00
$currency_code_options [ $code ] = $name . ' (' . get_woocommerce_currency_symbol ( $code ) . ')' ;
2014-04-08 22:11:33 +00:00
}
2013-07-26 14:36:28 +00:00
2014-09-12 11:20:06 +00:00
$settings = apply_filters ( 'woocommerce_general_settings' , array (
2013-07-26 14:36:28 +00:00
array ( 'title' => __ ( 'General Options' , 'woocommerce' ), 'type' => 'title' , 'desc' => '' , 'id' => 'general_options' ),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Base Location' , 'woocommerce' ),
'desc' => __ ( 'This is the base location for your business. Tax rates will be based on this country.' , 'woocommerce' ),
'id' => 'woocommerce_default_country' ,
'css' => 'min-width:350px;' ,
'default' => 'GB' ,
'type' => 'single_select_country' ,
'desc_tip' => true ,
2013-07-26 14:36:28 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Selling Location(s)' , 'woocommerce' ),
'desc' => __ ( 'This option lets you limit which countries you are willing to sell to.' , 'woocommerce' ),
'id' => 'woocommerce_allowed_countries' ,
'default' => 'all' ,
'type' => 'select' ,
'class' => 'chosen_select' ,
'css' => 'min-width: 350px;' ,
'desc_tip' => true ,
'options' => array (
2013-08-02 15:54:28 +00:00
'all' => __ ( 'Sell to all countries' , 'woocommerce' ),
'specific' => __ ( 'Sell to specific countries only' , 'woocommerce' )
2013-07-26 14:36:28 +00:00
)
),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Specific Countries' , 'woocommerce' ),
'desc' => '' ,
'id' => 'woocommerce_specific_allowed_countries' ,
'css' => 'min-width: 350px;' ,
'default' => '' ,
'type' => 'multi_select_countries'
2013-07-26 14:36:28 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Store Notice' , 'woocommerce' ),
'desc' => __ ( 'Enable site-wide store notice text' , 'woocommerce' ),
'id' => 'woocommerce_demo_store' ,
'default' => 'no' ,
'type' => 'checkbox'
2013-07-26 14:36:28 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Store Notice Text' , 'woocommerce' ),
'desc' => '' ,
'id' => 'woocommerce_demo_store_notice' ,
'default' => __ ( 'This is a demo store for testing purposes — no orders shall be fulfilled.' , 'woocommerce' ),
'type' => 'text' ,
'css' => 'min-width:300px;' ,
'autoload' => false
2013-07-26 14:36:28 +00:00
),
2013-11-19 08:01:46 +00:00
array (
'title' => __ ( 'API' , 'woocommerce' ),
'desc' => __ ( 'Enable the REST API' , 'woocommerce' ),
'id' => 'woocommerce_api_enabled' ,
'type' => 'checkbox' ,
'default' => 'yes' ,
),
2013-07-26 14:36:28 +00:00
array ( 'type' => 'sectionend' , 'id' => 'general_options' ),
2014-08-31 08:22:03 +00:00
array ( 'title' => __ ( 'Currency Options' , 'woocommerce' ), 'type' => 'title' , 'desc' => __ ( 'The following options affect how prices are displayed on the frontend.' , 'woocommerce' ), 'id' => 'pricing_options' ),
2013-07-26 14:36:28 +00:00
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Currency' , 'woocommerce' ),
'desc' => __ ( 'This controls what currency prices are listed at in the catalog and which currency gateways will take payments in.' , 'woocommerce' ),
'id' => 'woocommerce_currency' ,
'css' => 'min-width:350px;' ,
'default' => 'GBP' ,
'type' => 'select' ,
'class' => 'chosen_select' ,
'desc_tip' => true ,
'options' => $currency_code_options
2013-07-26 14:36:28 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Currency Position' , 'woocommerce' ),
'desc' => __ ( 'This controls the position of the currency symbol.' , 'woocommerce' ),
'id' => 'woocommerce_currency_pos' ,
'css' => 'min-width:350px;' ,
'class' => 'chosen_select' ,
'default' => 'left' ,
'type' => 'select' ,
'options' => array (
2013-08-22 10:58:03 +00:00
'left' => __ ( 'Left' , 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol () . '99.99)' ,
'right' => __ ( 'Right' , 'woocommerce' ) . ' (99.99' . get_woocommerce_currency_symbol () . ')' ,
'left_space' => __ ( 'Left with space' , 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol () . ' 99.99)' ,
'right_space' => __ ( 'Right with space' , 'woocommerce' ) . ' (99.99 ' . get_woocommerce_currency_symbol () . ')'
),
2014-08-31 08:22:03 +00:00
'desc_tip' => true ,
2013-07-26 14:36:28 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Thousand Separator' , 'woocommerce' ),
'desc' => __ ( 'This sets the thousand separator of displayed prices.' , 'woocommerce' ),
'id' => 'woocommerce_price_thousand_sep' ,
'css' => 'width:50px;' ,
'default' => ',' ,
'type' => 'text' ,
'desc_tip' => true ,
2013-07-26 14:36:28 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Decimal Separator' , 'woocommerce' ),
'desc' => __ ( 'This sets the decimal separator of displayed prices.' , 'woocommerce' ),
'id' => 'woocommerce_price_decimal_sep' ,
'css' => 'width:50px;' ,
'default' => '.' ,
'type' => 'text' ,
'desc_tip' => true ,
2013-07-26 14:36:28 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Number of Decimals' , 'woocommerce' ),
'desc' => __ ( 'This sets the number of decimal points shown in displayed prices.' , 'woocommerce' ),
'id' => 'woocommerce_price_num_decimals' ,
'css' => 'width:50px;' ,
'default' => '2' ,
'desc_tip' => true ,
'type' => 'number' ,
2013-08-22 10:58:03 +00:00
'custom_attributes' => array (
2014-08-31 08:22:03 +00:00
'min' => 0 ,
'step' => 1
2013-08-22 10:58:03 +00:00
)
2013-07-26 14:36:28 +00:00
),
2013-08-22 10:58:03 +00:00
array ( 'type' => 'sectionend' , 'id' => 'pricing_options' ),
2013-07-26 14:36:28 +00:00
2014-08-31 08:22:03 +00:00
array ( 'title' => __ ( 'Styles and Scripts' , 'woocommerce' ), 'type' => 'title' , 'id' => 'script_styling_options' ),
2013-07-26 14:36:28 +00:00
2014-08-31 08:22:03 +00:00
array ( 'type' => 'frontend_styles' ),
2013-07-26 14:36:28 +00:00
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Scripts' , 'woocommerce' ),
'desc' => __ ( 'Enable Lightbox' , 'woocommerce' ),
'id' => 'woocommerce_enable_lightbox' ,
'default' => 'yes' ,
'desc_tip' => __ ( 'Include WooCommerce\'s lightbox. Product gallery images will open in a lightbox.' , 'woocommerce' ),
'type' => 'checkbox' ,
'checkboxgroup' => 'start'
2013-07-26 14:36:28 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'desc' => __ ( 'Enable enhanced country select boxes' , 'woocommerce' ),
'id' => 'woocommerce_enable_chosen' ,
'default' => 'yes' ,
'type' => 'checkbox' ,
'checkboxgroup' => 'end' ,
'desc_tip' => __ ( 'This will enable a script allowing the country fields to be searchable.' , 'woocommerce' ),
'autoload' => false
2013-07-26 14:36:28 +00:00
),
2013-08-22 10:58:03 +00:00
array ( 'type' => 'sectionend' , 'id' => 'script_styling_options' ),
2013-07-26 14:36:28 +00:00
2014-09-12 11:20:06 +00:00
) );
return apply_filters ( 'woocommerce_get_settings_' . $this -> id , $settings );
2013-07-26 14:36:28 +00:00
}
/**
* Output the frontend styles settings .
*/
public function frontend_styles_setting () {
2014-08-31 08:22:03 +00:00
2013-07-26 14:36:28 +00:00
?> <tr valign="top" class="woocommerce_frontend_css_colors">
< th scope = " row " class = " titledesc " >
2013-08-22 10:58:03 +00:00
< ? php _e ( 'Frontend Styles' , 'woocommerce' ); ?>
2013-07-26 14:36:28 +00:00
</ th >
2014-04-08 22:11:33 +00:00
< td class = " forminp " >< ? php
2013-07-26 14:36:28 +00:00
2014-09-22 18:30:07 +00:00
$base_file = WC () -> plugin_path () . '/assets/css/_woocommerce-base.scss' ;
2014-04-08 22:11:33 +00:00
$css_file = WC () -> plugin_path () . '/assets/css/woocommerce.css' ;
2013-07-26 14:36:28 +00:00
if ( is_writable ( $base_file ) && is_writable ( $css_file ) ) {
// Get settings
$colors = array_map ( 'esc_attr' , ( array ) get_option ( 'woocommerce_frontend_css_colors' ) );
// Defaults
2014-04-08 22:11:33 +00:00
if ( empty ( $colors [ 'primary' ] ) ) {
$colors [ 'primary' ] = '#ad74a2' ;
}
if ( empty ( $colors [ 'secondary' ] ) ) {
$colors [ 'secondary' ] = '#f7f6f7' ;
}
if ( empty ( $colors [ 'highlight' ] ) ) {
$colors [ 'highlight' ] = '#85ad74' ;
}
if ( empty ( $colors [ 'content_bg' ] ) ) {
$colors [ 'content_bg' ] = '#ffffff' ;
}
if ( empty ( $colors [ 'subtext' ] ) ) {
$colors [ 'subtext' ] = '#777777' ;
}
2013-07-26 14:36:28 +00:00
// Show inputs
2014-04-08 22:11:33 +00:00
$this -> color_picker ( __ ( 'Primary' , 'woocommerce' ), 'woocommerce_frontend_css_primary' , $colors [ 'primary' ], __ ( 'Call to action buttons/price slider/layered nav UI' , 'woocommerce' ) );
$this -> color_picker ( __ ( 'Secondary' , 'woocommerce' ), 'woocommerce_frontend_css_secondary' , $colors [ 'secondary' ], __ ( 'Buttons and tabs' , 'woocommerce' ) );
$this -> color_picker ( __ ( 'Highlight' , 'woocommerce' ), 'woocommerce_frontend_css_highlight' , $colors [ 'highlight' ], __ ( 'Price labels and Sale Flashes' , 'woocommerce' ) );
$this -> color_picker ( __ ( 'Content' , 'woocommerce' ), 'woocommerce_frontend_css_content_bg' , $colors [ 'content_bg' ], __ ( 'Your themes page background - used for tab active states' , 'woocommerce' ) );
$this -> color_picker ( __ ( 'Subtext' , 'woocommerce' ), 'woocommerce_frontend_css_subtext' , $colors [ 'subtext' ], __ ( 'Used for certain text and asides - breadcrumbs, small text etc.' , 'woocommerce' ) );
} else {
2014-09-22 18:30:07 +00:00
echo '<span class="description">' . __ ( 'To edit colours <code>woocommerce/assets/css/_woocommerce-base.scss</code> and <code>woocommerce.css</code> need to be writable. See <a href="http://codex.wordpress.org/Changing_File_Permissions">the Codex</a> for more information.' , 'woocommerce' ) . '</span>' ;
2014-04-08 22:11:33 +00:00
}
2013-07-26 14:36:28 +00:00
2014-04-08 22:11:33 +00:00
?> </td>
2013-07-26 14:36:28 +00:00
</ tr >< ? php
}
/**
* Output a colour picker input box .
*
* @ param mixed $name
2014-09-07 23:37:55 +00:00
* @ param string $id
2013-07-26 14:36:28 +00:00
* @ param mixed $value
* @ param string $desc ( default : '' )
*/
2014-08-31 08:22:03 +00:00
public function color_picker ( $name , $id , $value , $desc = '' ) {
2013-07-26 14:36:28 +00:00
echo '<div class="color_box"><strong><img class="help_tip" data-tip="' . esc_attr ( $desc ) . '" src="' . WC () -> plugin_url () . '/assets/images/help.png" height="16" width="16" /> ' . esc_html ( $name ) . ' </ strong >
2014-04-08 22:11:33 +00:00
< 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 >
</ div > ' ;
2013-07-26 14:36:28 +00:00
}
/**
* Save settings
*/
public function save () {
$settings = $this -> get_settings ();
WC_Admin_Settings :: save_fields ( $settings );
if ( isset ( $_POST [ 'woocommerce_frontend_css_primary' ] ) ) {
// Save settings
2014-04-08 22:11:33 +00:00
$primary = ( ! empty ( $_POST [ 'woocommerce_frontend_css_primary' ] ) ) ? wc_format_hex ( $_POST [ 'woocommerce_frontend_css_primary' ] ) : '' ;
$secondary = ( ! empty ( $_POST [ 'woocommerce_frontend_css_secondary' ] ) ) ? wc_format_hex ( $_POST [ 'woocommerce_frontend_css_secondary' ] ) : '' ;
$highlight = ( ! empty ( $_POST [ 'woocommerce_frontend_css_highlight' ] ) ) ? wc_format_hex ( $_POST [ 'woocommerce_frontend_css_highlight' ] ) : '' ;
$content_bg = ( ! empty ( $_POST [ 'woocommerce_frontend_css_content_bg' ] ) ) ? wc_format_hex ( $_POST [ 'woocommerce_frontend_css_content_bg' ] ) : '' ;
$subtext = ( ! empty ( $_POST [ 'woocommerce_frontend_css_subtext' ] ) ) ? wc_format_hex ( $_POST [ 'woocommerce_frontend_css_subtext' ] ) : '' ;
2013-07-26 14:36:28 +00:00
$colors = array (
2014-04-08 22:11:33 +00:00
'primary' => $primary ,
'secondary' => $secondary ,
'highlight' => $highlight ,
'content_bg' => $content_bg ,
'subtext' => $subtext
2013-07-26 14:36:28 +00:00
);
2014-04-08 22:08:04 +00:00
// Check the colors.
$valid_colors = true ;
foreach ( $colors as $color ) {
2014-08-31 08:22:03 +00:00
2014-04-08 22:08:04 +00:00
if ( ! preg_match ( '/^#[a-f0-9]{6}$/i' , $color ) ) {
$valid_colors = false ;
WC_Admin_Settings :: add_error ( sprintf ( __ ( 'Error saving the Frontend Styles, %s is not a valid color, please use only valid colors code.' , 'woocommerce' ), $color ) );
break ;
}
}
if ( $valid_colors ) {
$old_colors = get_option ( 'woocommerce_frontend_css_colors' );
update_option ( 'woocommerce_frontend_css_colors' , $colors );
if ( $old_colors != $colors ) {
2014-09-22 18:30:07 +00:00
woocommerce_compile_scss_styles ();
2014-04-08 22:08:04 +00:00
}
}
2013-07-26 14:36:28 +00:00
}
}
}
endif ;
2013-11-19 08:01:46 +00:00
return new WC_Settings_General ();