2017-11-14 16:01:36 +00:00
< ? php
/**
* Adds options to the customizer for WooCommerce .
*
* @ version 3.3 . 0
* @ package WooCommerce
*/
2018-01-25 11:38:05 +00:00
defined ( 'ABSPATH' ) || exit ;
2017-11-14 16:01:36 +00:00
/**
2017-12-12 22:01:34 +00:00
* WC_Shop_Customizer class .
2017-11-14 16:01:36 +00:00
*/
2017-12-12 22:01:34 +00:00
class WC_Shop_Customizer {
2017-11-14 16:01:36 +00:00
/**
* Constructor .
*/
public function __construct () {
add_action ( 'customize_register' , array ( $this , 'add_sections' ) );
add_action ( 'customize_controls_print_styles' , array ( $this , 'add_styles' ) );
add_action ( 'customize_controls_print_scripts' , array ( $this , 'add_scripts' ), 30 );
2018-02-27 19:52:31 +00:00
add_action ( 'wp_enqueue_scripts' , array ( $this , 'add_frontend_scripts' ) );
2017-11-14 16:01:36 +00:00
}
/**
* Add settings to the customizer .
*
* @ param WP_Customize_Manager $wp_customize Theme Customizer object .
*/
public function add_sections ( $wp_customize ) {
2017-11-15 15:05:31 +00:00
$wp_customize -> add_panel ( 'woocommerce' , array (
'priority' => 200 ,
'capability' => 'manage_woocommerce' ,
'theme_supports' => '' ,
'title' => __ ( 'WooCommerce' , 'woocommerce' ),
) );
$this -> add_store_notice_section ( $wp_customize );
2017-12-14 03:04:52 +00:00
$this -> add_product_catalog_section ( $wp_customize );
2017-11-15 15:05:31 +00:00
$this -> add_product_images_section ( $wp_customize );
2018-04-05 12:55:15 +00:00
$this -> add_checkout_section ( $wp_customize );
2017-11-15 15:05:31 +00:00
}
2017-11-14 16:29:17 +00:00
2018-02-27 19:52:31 +00:00
/**
* Frontend CSS styles .
*/
public function add_frontend_scripts () {
if ( ! is_customize_preview () || ! is_store_notice_showing () ) {
return ;
}
$css = '.woocommerce-store-notice, p.demo_store { display: block !important; }' ;
wp_add_inline_style ( 'customize-preview' , $css );
}
2017-11-15 15:05:31 +00:00
/**
* CSS styles to improve our form .
*/
public function add_styles () {
?>
< style type = " text/css " >
. woocommerce - cropping - control {
margin : 0 40 px 1 em 0 ;
padding : 0 ;
display : inline - block ;
vertical - align : top ;
}
. woocommerce - cropping - control input [ type = radio ] {
margin - top : 1 px ;
}
. woocommerce - cropping - control span . woocommerce - cropping - control - aspect - ratio {
margin - top : . 5 em ;
display : block ;
}
. woocommerce - cropping - control span . woocommerce - cropping - control - aspect - ratio input {
width : auto ;
display : inline - block ;
}
</ style >
< ? php
}
/**
* Scripts to improve our form .
*/
public function add_scripts () {
2018-01-08 18:48:57 +00:00
$min_rows = wc_get_theme_support ( 'product_grid::min_rows' , 1 );
$max_rows = wc_get_theme_support ( 'product_grid::max_rows' , '' );
$min_columns = wc_get_theme_support ( 'product_grid::min_columns' , 1 );
$max_columns = wc_get_theme_support ( 'product_grid::max_columns' , '' );
2018-01-25 11:38:05 +00:00
/* translators: %d: Setting value */
$min_notice = __ ( 'The minimum allowed setting is %d' , 'woocommerce' );
/* translators: %d: Setting value */
$max_notice = __ ( 'The maximum allowed setting is %d' , 'woocommerce' );
2017-11-15 15:05:31 +00:00
?>
< script type = " text/javascript " >
jQuery ( document ) . ready ( function ( $ ) {
$ ( document . body ) . on ( 'change' , '.woocommerce-cropping-control input[type="radio"]' , function () {
var $wrapper = $ ( this ) . closest ( '.woocommerce-cropping-control' ),
value = $wrapper . find ( 'input:checked' ) . val ();
if ( 'custom' === value ) {
$wrapper . find ( '.woocommerce-cropping-control-aspect-ratio' ) . slideDown ( 200 );
} else {
$wrapper . find ( '.woocommerce-cropping-control-aspect-ratio' ) . hide ();
}
return false ;
} );
wp . customize . bind ( 'ready' , function () { // Ready?
$ ( '.woocommerce-cropping-control' ) . find ( 'input:checked' ) . change ();
} );
2018-01-08 18:48:57 +00:00
2018-02-27 19:52:31 +00:00
wp . customize ( 'woocommerce_demo_store' , function ( setting ) {
setting . bind ( function ( value ) {
var notice = wp . customize ( 'woocommerce_demo_store_notice' );
if ( value && ! notice . callbacks . has ( notice . preview ) ) {
notice . bind ( notice . preview );
} else if ( ! value ) {
notice . unbind ( notice . preview );
}
} );
} );
2018-02-27 12:46:36 +00:00
wp . customize ( 'woocommerce_demo_store_notice' , function ( setting ) {
setting . bind ( function ( value ) {
var checkbox = wp . customize ( 'woocommerce_demo_store' );
if ( checkbox . get () ) {
$ ( '.woocommerce-store-notice' ) . text ( value );
}
} );
} );
2018-02-28 11:58:04 +00:00
wp . customize . section ( 'woocommerce_store_notice' , function ( section ) {
section . expanded . bind ( function ( isExpanded ) {
if ( isExpanded ) {
var notice = wp . customize ( 'woocommerce_demo_store_notice' ),
checkbox = wp . customize ( 'woocommerce_demo_store' );
if ( checkbox . get () && ! notice . callbacks . has ( notice . preview ) ) {
notice . bind ( notice . preview );
} else if ( ! checkbox . get () ) {
notice . unbind ( notice . preview );
}
}
} );
} );
2018-01-25 11:48:45 +00:00
wp . customize . section ( 'woocommerce_product_catalog' , function ( section ) {
section . expanded . bind ( function ( isExpanded ) {
if ( isExpanded ) {
wp . customize . previewer . previewUrl . set ( '<?php echo esc_js( wc_get_page_permalink( ' shop ' ) ); ?>' );
}
} );
} );
wp . customize . section ( 'woocommerce_product_images' , function ( section ) {
section . expanded . bind ( function ( isExpanded ) {
if ( isExpanded ) {
wp . customize . previewer . previewUrl . set ( '<?php echo esc_js( wc_get_page_permalink( ' shop ' ) ); ?>' );
}
} );
} );
2018-01-08 18:48:57 +00:00
wp . customize ( 'woocommerce_catalog_columns' , function ( setting ) {
setting . bind ( function ( value ) {
2018-01-26 15:54:34 +00:00
var min = parseInt ( '<?php echo esc_js( $min_columns ); ?>' , 10 );
var max = parseInt ( '<?php echo esc_js( $max_columns ); ?>' , 10 );
2018-01-26 15:53:23 +00:00
2018-01-26 15:54:34 +00:00
value = parseInt ( value , 10 );
2018-01-08 18:48:57 +00:00
if ( max && value > max ) {
setting . notifications . add ( 'max_columns_error' , new wp . customize . Notification (
'max_columns_error' ,
{
type : 'error' ,
2018-01-25 11:38:05 +00:00
message : '<?php echo esc_js( sprintf( $max_notice, $max_columns ) ); ?>'
2018-01-08 18:48:57 +00:00
}
) );
} else {
setting . notifications . remove ( 'max_columns_error' );
}
if ( min && value < min ) {
setting . notifications . add ( 'min_columns_error' , new wp . customize . Notification (
'min_columns_error' ,
{
type : 'error' ,
2018-01-25 11:38:05 +00:00
message : '<?php echo esc_js( sprintf( $min_notice, $min_columns ) ); ?>'
2018-01-08 18:48:57 +00:00
}
) );
} else {
setting . notifications . remove ( 'min_columns_error' );
}
} );
} );
wp . customize ( 'woocommerce_catalog_rows' , function ( setting ) {
setting . bind ( function ( value ) {
2018-02-06 07:50:23 +00:00
var min = parseInt ( '<?php echo esc_js( $min_rows ); ?>' , 10 );
var max = parseInt ( '<?php echo esc_js( $max_rows ); ?>' , 10 );
2018-02-12 17:47:22 +00:00
2018-02-06 07:50:23 +00:00
value = parseInt ( value , 10 );
2018-01-08 18:48:57 +00:00
if ( max && value > max ) {
setting . notifications . add ( 'max_rows_error' , new wp . customize . Notification (
'max_rows_error' ,
{
type : 'error' ,
2018-01-25 11:38:05 +00:00
message : '<?php echo esc_js( sprintf( $min_notice, $max_rows ) ); ?>'
2018-01-08 18:48:57 +00:00
}
) );
} else {
setting . notifications . remove ( 'max_rows_error' );
}
if ( min && value < min ) {
setting . notifications . add ( 'min_rows_error' , new wp . customize . Notification (
'min_rows_error' ,
{
type : 'error' ,
2018-01-25 11:38:05 +00:00
message : '<?php echo esc_js( sprintf( $min_notice, $min_rows ) ); ?>'
2018-01-08 18:48:57 +00:00
}
) );
} else {
setting . notifications . remove ( 'min_rows_error' );
}
} );
} );
2017-11-15 15:05:31 +00:00
} );
</ script >
< ? php
}
2017-12-12 04:30:14 +00:00
/**
* Sanitize the shop page & category display setting .
*
2017-12-12 22:01:34 +00:00
* @ param string $value '' , 'subcategories' , or 'both' .
2017-12-12 05:42:48 +00:00
* @ return string
2017-12-12 04:30:14 +00:00
*/
public function sanitize_archive_display ( $value ) {
$options = array ( '' , 'subcategories' , 'both' );
2018-01-25 11:38:05 +00:00
return in_array ( $value , $options , true ) ? $value : '' ;
2017-12-12 04:30:14 +00:00
}
/**
* Sanitize the catalog orderby setting .
*
2017-12-12 22:01:34 +00:00
* @ param string $value An array key from the below array .
2017-12-12 05:42:48 +00:00
* @ return string
2017-12-12 04:30:14 +00:00
*/
public function sanitize_default_catalog_orderby ( $value ) {
$options = apply_filters ( 'woocommerce_default_catalog_orderby_options' , array (
'menu_order' => __ ( 'Default sorting (custom ordering + name)' , 'woocommerce' ),
'popularity' => __ ( 'Popularity (sales)' , 'woocommerce' ),
'rating' => __ ( 'Average rating' , 'woocommerce' ),
'date' => __ ( 'Sort by most recent' , 'woocommerce' ),
'price' => __ ( 'Sort by price (asc)' , 'woocommerce' ),
'price-desc' => __ ( 'Sort by price (desc)' , 'woocommerce' ),
) );
return array_key_exists ( $value , $options ) ? $value : 'menu_order' ;
}
2017-11-15 15:05:31 +00:00
/**
* Store notice section .
*
* @ param WP_Customize_Manager $wp_customize Theme Customizer object .
*/
private function add_store_notice_section ( $wp_customize ) {
2017-11-14 16:29:17 +00:00
$wp_customize -> add_section (
2017-11-15 15:05:31 +00:00
'woocommerce_store_notice' ,
2017-11-14 16:29:17 +00:00
array (
2017-11-15 15:05:31 +00:00
'title' => __ ( 'Store Notice' , 'woocommerce' ),
'priority' => 10 ,
'panel' => 'woocommerce' ,
2017-11-14 16:01:36 +00:00
)
);
$wp_customize -> add_setting (
'woocommerce_demo_store' ,
array (
'default' => 'no' ,
'type' => 'option' ,
'capability' => 'manage_woocommerce' ,
'sanitize_callback' => 'wc_bool_to_string' ,
'sanitize_js_callback' => 'wc_string_to_bool' ,
)
);
$wp_customize -> add_setting (
'woocommerce_demo_store_notice' ,
array (
'default' => __ ( 'This is a demo store for testing purposes — no orders shall be fulfilled.' , 'woocommerce' ),
'type' => 'option' ,
'capability' => 'manage_woocommerce' ,
'sanitize_callback' => 'wp_kses_post' ,
2018-02-27 12:46:36 +00:00
'transport' => 'postMessage' ,
2017-11-14 16:01:36 +00:00
)
);
$wp_customize -> add_control (
'woocommerce_demo_store_notice' ,
array (
'label' => __ ( 'Store notice' , 'woocommerce' ),
2017-11-14 16:29:17 +00:00
'description' => __ ( 'If enabled, this text will be shown site-wide. You can use it to show events or promotions to visitors!' , 'woocommerce' ),
2017-11-15 15:05:31 +00:00
'section' => 'woocommerce_store_notice' ,
2017-11-14 16:01:36 +00:00
'settings' => 'woocommerce_demo_store_notice' ,
'type' => 'textarea' ,
)
);
$wp_customize -> add_control (
'woocommerce_demo_store' ,
array (
2018-01-25 11:38:05 +00:00
'label' => __ ( 'Enable store notice' , 'woocommerce' ),
'section' => 'woocommerce_store_notice' ,
'settings' => 'woocommerce_demo_store' ,
'type' => 'checkbox' ,
2017-11-14 16:01:36 +00:00
)
);
2018-02-27 12:46:36 +00:00
if ( isset ( $wp_customize -> selective_refresh ) ) {
$wp_customize -> selective_refresh -> add_partial (
'woocommerce_demo_store_notice' , array (
'selector' => '.woocommerce-store-notice' ,
'container_inclusive' => true ,
'render_callback' => 'woocommerce_demo_store' ,
)
);
}
2017-11-15 15:05:31 +00:00
}
2017-11-14 16:01:36 +00:00
2017-11-15 15:05:31 +00:00
/**
2017-12-14 03:04:52 +00:00
* Product catalog section .
2017-11-15 15:05:31 +00:00
*
* @ param WP_Customize_Manager $wp_customize Theme Customizer object .
*/
2017-12-14 03:04:52 +00:00
public function add_product_catalog_section ( $wp_customize ) {
2017-11-15 15:05:31 +00:00
$wp_customize -> add_section (
2017-12-14 03:04:52 +00:00
'woocommerce_product_catalog' ,
2017-11-15 15:05:31 +00:00
array (
2018-01-25 11:48:45 +00:00
'title' => __ ( 'Product Catalog' , 'woocommerce' ),
'priority' => 10 ,
'panel' => 'woocommerce' ,
2017-11-15 15:05:31 +00:00
)
);
2017-11-14 16:38:39 +00:00
2017-12-12 04:30:14 +00:00
$wp_customize -> add_setting (
'woocommerce_shop_page_display' ,
array (
2018-01-25 11:38:05 +00:00
'default' => '' ,
'type' => 'option' ,
'capability' => 'manage_woocommerce' ,
'sanitize_callback' => array ( $this , 'sanitize_archive_display' ),
2017-12-12 04:30:14 +00:00
)
);
$wp_customize -> add_control (
'woocommerce_shop_page_display' ,
array (
'label' => __ ( 'Shop page display' , 'woocommerce' ),
2017-12-14 03:01:40 +00:00
'description' => __ ( 'Choose what to display on the main shop page.' , 'woocommerce' ),
2017-12-14 03:04:52 +00:00
'section' => 'woocommerce_product_catalog' ,
2017-12-12 04:30:14 +00:00
'settings' => 'woocommerce_shop_page_display' ,
'type' => 'select' ,
'choices' => array (
'' => __ ( 'Show products' , 'woocommerce' ),
'subcategories' => __ ( 'Show categories' , 'woocommerce' ),
'both' => __ ( 'Show categories & products' , 'woocommerce' ),
),
)
);
$wp_customize -> add_setting (
'woocommerce_category_archive_display' ,
array (
2018-01-25 11:38:05 +00:00
'default' => '' ,
'type' => 'option' ,
'capability' => 'manage_woocommerce' ,
'sanitize_callback' => array ( $this , 'sanitize_archive_display' ),
2017-12-12 04:30:14 +00:00
)
);
$wp_customize -> add_control (
'woocommerce_category_archive_display' ,
array (
2017-12-14 03:01:40 +00:00
'label' => __ ( 'Category display' , 'woocommerce' ),
'description' => __ ( 'Choose what to display on product category pages.' , 'woocommerce' ),
2017-12-14 03:04:52 +00:00
'section' => 'woocommerce_product_catalog' ,
2017-12-12 04:30:14 +00:00
'settings' => 'woocommerce_category_archive_display' ,
'type' => 'select' ,
'choices' => array (
'' => __ ( 'Show products' , 'woocommerce' ),
2017-12-14 02:49:47 +00:00
'subcategories' => __ ( 'Show subcategories' , 'woocommerce' ),
2017-12-12 04:30:14 +00:00
'both' => __ ( 'Show subcategories & products' , 'woocommerce' ),
),
)
);
$wp_customize -> add_setting (
'woocommerce_default_catalog_orderby' ,
array (
2018-01-25 11:38:05 +00:00
'default' => 'menu_order' ,
'type' => 'option' ,
'capability' => 'manage_woocommerce' ,
'sanitize_callback' => array ( $this , 'sanitize_default_catalog_orderby' ),
2017-12-12 04:30:14 +00:00
)
);
$wp_customize -> add_control (
'woocommerce_default_catalog_orderby' ,
array (
'label' => __ ( 'Default product sorting' , 'woocommerce' ),
2018-01-31 06:06:51 +00:00
'description' => __ ( 'How should products be sorted in the catalog by default?' , 'woocommerce' ),
2017-12-14 03:04:52 +00:00
'section' => 'woocommerce_product_catalog' ,
2017-12-12 04:30:14 +00:00
'settings' => 'woocommerce_default_catalog_orderby' ,
'type' => 'select' ,
'choices' => apply_filters ( 'woocommerce_default_catalog_orderby_options' , array (
'menu_order' => __ ( 'Default sorting (custom ordering + name)' , 'woocommerce' ),
'popularity' => __ ( 'Popularity (sales)' , 'woocommerce' ),
'rating' => __ ( 'Average rating' , 'woocommerce' ),
'date' => __ ( 'Sort by most recent' , 'woocommerce' ),
'price' => __ ( 'Sort by price (asc)' , 'woocommerce' ),
'price-desc' => __ ( 'Sort by price (desc)' , 'woocommerce' ),
) ),
)
);
2017-12-12 04:36:39 +00:00
// The following settings should be hidden if the theme is declaring the values.
if ( has_filter ( 'loop_shop_columns' ) ) {
return ;
}
2017-11-15 15:05:31 +00:00
$wp_customize -> add_setting (
'woocommerce_catalog_columns' ,
array (
2018-01-31 17:55:17 +00:00
'default' => 4 ,
2017-11-15 15:05:31 +00:00
'type' => 'option' ,
'capability' => 'manage_woocommerce' ,
'sanitize_callback' => 'absint' ,
'sanitize_js_callback' => 'absint' ,
)
);
2017-11-14 16:38:39 +00:00
2017-11-15 15:05:31 +00:00
$wp_customize -> add_control (
'woocommerce_catalog_columns' ,
array (
'label' => __ ( 'Products per row' , 'woocommerce' ),
'description' => __ ( 'How many products should be shown per row?' , 'woocommerce' ),
2017-12-14 03:04:52 +00:00
'section' => 'woocommerce_product_catalog' ,
2017-11-15 15:05:31 +00:00
'settings' => 'woocommerce_catalog_columns' ,
'type' => 'number' ,
'input_attrs' => array (
2018-01-08 18:48:57 +00:00
'min' => wc_get_theme_support ( 'product_grid::min_columns' , 1 ),
'max' => wc_get_theme_support ( 'product_grid::max_columns' , '' ),
2017-11-15 15:05:31 +00:00
'step' => 1 ,
),
)
);
2018-01-31 23:50:48 +00:00
// Only add this setting if something else isn't managing the number of products per page.
if ( ! has_filter ( 'loop_shop_per_page' ) ) {
$wp_customize -> add_setting (
'woocommerce_catalog_rows' ,
array (
'default' => 4 ,
'type' => 'option' ,
'capability' => 'manage_woocommerce' ,
'sanitize_callback' => 'absint' ,
'sanitize_js_callback' => 'absint' ,
)
);
}
2017-11-15 15:05:31 +00:00
$wp_customize -> add_control (
'woocommerce_catalog_rows' ,
array (
'label' => __ ( 'Rows per page' , 'woocommerce' ),
'description' => __ ( 'How many rows of products should be shown per page?' , 'woocommerce' ),
2017-12-14 03:04:52 +00:00
'section' => 'woocommerce_product_catalog' ,
2017-11-15 15:05:31 +00:00
'settings' => 'woocommerce_catalog_rows' ,
'type' => 'number' ,
'input_attrs' => array (
2018-01-08 18:48:57 +00:00
'min' => wc_get_theme_support ( 'product_grid::min_rows' , 1 ),
'max' => wc_get_theme_support ( 'product_grid::max_rows' , '' ),
2017-11-15 15:05:31 +00:00
'step' => 1 ,
),
)
);
}
/**
* Product images section .
*
* @ param WP_Customize_Manager $wp_customize Theme Customizer object .
*/
private function add_product_images_section ( $wp_customize ) {
2018-02-14 17:25:52 +00:00
if ( class_exists ( 'Jetpack' ) && Jetpack :: is_module_active ( 'photon' ) ) {
$regen_description = '' ; // Nothing to report; Jetpack will handle magically.
} elseif ( apply_filters ( 'woocommerce_background_image_regeneration' , true ) && ! is_multisite () ) {
$regen_description = __ ( 'After publishing your changes, new image sizes will be generated automatically.' , 'woocommerce' );
} elseif ( apply_filters ( 'woocommerce_background_image_regeneration' , true ) && is_multisite () ) {
2018-02-27 12:46:36 +00:00
/* translators: 1: tools URL 2: regen thumbs url */
2018-02-14 17:25:52 +00:00
$regen_description = sprintf ( __ ( 'After publishing your changes, new image sizes may not be shown until you regenerate thumbnails. You can do this from the <a href="%1$s" target="_blank">tools section in WooCommerce</a> or by using a plugin such as <a href="%2$s" target="_blank">Regenerate Thumbnails</a>.' , 'woocommerce' ), admin_url ( 'admin.php?page=wc-status&tab=tools' ), 'https://en-gb.wordpress.org/plugins/regenerate-thumbnails/' );
} else {
2018-02-27 12:46:36 +00:00
/* translators: %s: regen thumbs url */
$regen_description = sprintf ( __ ( 'After publishing your changes, new image sizes may not be shown until you <a href="%s" target="_blank">Regenerate Thumbnails</a>.' , 'woocommerce' ), 'https://en-gb.wordpress.org/plugins/regenerate-thumbnails/' );
2018-02-14 17:25:52 +00:00
}
2017-11-15 15:05:31 +00:00
$wp_customize -> add_section (
'woocommerce_product_images' ,
array (
2018-02-14 17:25:52 +00:00
'title' => __ ( 'Product Images' , 'woocommerce' ),
'description' => $regen_description ,
'priority' => 20 ,
'panel' => 'woocommerce' ,
2017-11-15 15:05:31 +00:00
)
);
2017-11-14 16:29:17 +00:00
2018-01-08 18:48:57 +00:00
if ( ! wc_get_theme_support ( 'single_image_width' ) ) {
2017-11-14 16:38:39 +00:00
$wp_customize -> add_setting (
2017-12-14 02:41:53 +00:00
'woocommerce_single_image_width' ,
2017-11-14 16:38:39 +00:00
array (
'default' => 600 ,
'type' => 'option' ,
'capability' => 'manage_woocommerce' ,
'sanitize_callback' => 'absint' ,
'sanitize_js_callback' => 'absint' ,
)
);
$wp_customize -> add_control (
2017-12-14 02:41:53 +00:00
'woocommerce_single_image_width' ,
2017-11-14 16:38:39 +00:00
array (
'label' => __ ( 'Main image width' , 'woocommerce' ),
2017-12-14 03:22:38 +00:00
'description' => __ ( 'Image size used for the main image on single product pages. These images will remain uncropped.' , 'woocommerce' ),
2017-11-15 15:05:31 +00:00
'section' => 'woocommerce_product_images' ,
2017-12-14 02:41:53 +00:00
'settings' => 'woocommerce_single_image_width' ,
2017-11-14 16:38:39 +00:00
'type' => 'number' ,
'input_attrs' => array (
'min' => 0 ,
'step' => 1 ,
),
)
);
}
2018-01-08 18:48:57 +00:00
if ( ! wc_get_theme_support ( 'thumbnail_image_width' ) ) {
2017-11-14 16:38:39 +00:00
$wp_customize -> add_setting (
2017-12-14 02:41:53 +00:00
'woocommerce_thumbnail_image_width' ,
2017-11-14 16:38:39 +00:00
array (
'default' => 300 ,
'type' => 'option' ,
'capability' => 'manage_woocommerce' ,
'sanitize_callback' => 'absint' ,
'sanitize_js_callback' => 'absint' ,
)
);
$wp_customize -> add_control (
2017-12-14 02:41:53 +00:00
'woocommerce_thumbnail_image_width' ,
2017-11-14 16:38:39 +00:00
array (
'label' => __ ( 'Thumbnail width' , 'woocommerce' ),
2018-02-12 17:47:22 +00:00
'description' => __ ( 'Image size used for products in the catalog.' , 'woocommerce' ),
2017-11-15 15:05:31 +00:00
'section' => 'woocommerce_product_images' ,
2017-12-14 02:41:53 +00:00
'settings' => 'woocommerce_thumbnail_image_width' ,
2017-11-14 16:38:39 +00:00
'type' => 'number' ,
2017-12-12 22:01:34 +00:00
'input_attrs' => array (
'min' => 0 ,
'step' => 1 ,
),
2017-11-14 16:38:39 +00:00
)
);
}
2017-11-14 16:01:36 +00:00
2018-01-25 11:38:05 +00:00
include_once WC_ABSPATH . 'includes/customizer/class-wc-customizer-control-cropping.php' ;
2017-11-14 16:01:36 +00:00
$wp_customize -> add_setting (
'woocommerce_thumbnail_cropping' ,
array (
2018-01-25 15:14:02 +00:00
'default' => '1:1' ,
2018-01-25 11:38:05 +00:00
'type' => 'option' ,
'capability' => 'manage_woocommerce' ,
'sanitize_callback' => 'wc_clean' ,
2017-11-14 16:01:36 +00:00
)
);
$wp_customize -> add_setting (
'woocommerce_thumbnail_cropping_custom_width' ,
array (
'default' => '4' ,
'type' => 'option' ,
'capability' => 'manage_woocommerce' ,
'sanitize_callback' => 'absint' ,
'sanitize_js_callback' => 'absint' ,
)
);
$wp_customize -> add_setting (
'woocommerce_thumbnail_cropping_custom_height' ,
array (
'default' => '3' ,
'type' => 'option' ,
'capability' => 'manage_woocommerce' ,
'sanitize_callback' => 'absint' ,
'sanitize_js_callback' => 'absint' ,
)
);
$wp_customize -> add_control (
new WC_Customizer_Control_Cropping (
$wp_customize ,
'woocommerce_thumbnail_cropping' ,
array (
2017-11-15 15:05:31 +00:00
'section' => 'woocommerce_product_images' ,
2017-11-14 16:01:36 +00:00
'settings' => array (
'cropping' => 'woocommerce_thumbnail_cropping' ,
'custom_width' => 'woocommerce_thumbnail_cropping_custom_width' ,
'custom_height' => 'woocommerce_thumbnail_cropping_custom_height' ,
),
'label' => __ ( 'Thumbnail cropping' , 'woocommerce' ),
'choices' => array (
2018-01-25 11:38:05 +00:00
'1:1' => array (
2017-11-14 16:01:36 +00:00
'label' => __ ( '1:1' , 'woocommerce' ),
'description' => __ ( 'Images will be cropped into a square' , 'woocommerce' ),
),
2018-01-25 11:38:05 +00:00
'custom' => array (
2017-11-14 16:01:36 +00:00
'label' => __ ( 'Custom' , 'woocommerce' ),
'description' => __ ( 'Images will be cropped to a custom aspect ratio' , 'woocommerce' ),
),
2018-01-25 11:38:05 +00:00
'uncropped' => array (
2017-11-14 16:01:36 +00:00
'label' => __ ( 'Uncropped' , 'woocommerce' ),
'description' => __ ( 'Images will display using the aspect ratio in which they were uploaded' , 'woocommerce' ),
),
),
)
)
);
}
2018-04-05 12:55:15 +00:00
/**
* Checkout section .
*
* @ param WP_Customize_Manager $wp_customize Theme Customizer object .
*/
public function add_checkout_section ( $wp_customize ) {
$wp_customize -> add_section (
'woocommerce_checkout' ,
array (
'title' => __ ( 'Checkout Form Options' , 'woocommerce' ),
'priority' => 20 ,
'panel' => 'woocommerce' ,
'description' => __ ( 'These options let you change the appearance of certain parts of the WooCommerce checkout form.' , 'woocommerce' ),
)
);
}
2017-11-14 16:01:36 +00:00
}
2017-12-12 22:01:34 +00:00
new WC_Shop_Customizer ();