WC_Twenty_Twenty
WC_Twenty_Twenty class.
Description Description
Source Source
File: includes/theme-support/class-wc-twenty-twenty.php
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | class WC_Twenty_Twenty { /** * Theme init. */ public static function init() { // Change WooCommerce wrappers. remove_action( 'woocommerce_before_main_content' , 'woocommerce_output_content_wrapper' , 10 ); remove_action( 'woocommerce_after_main_content' , 'woocommerce_output_content_wrapper_end' , 10 ); add_action( 'woocommerce_before_main_content' , array ( __CLASS__ , 'output_content_wrapper' ), 10 ); add_action( 'woocommerce_after_main_content' , array ( __CLASS__ , 'output_content_wrapper_end' ), 10 ); // This theme doesn't have a traditional sidebar. remove_action( 'woocommerce_sidebar' , 'woocommerce_get_sidebar' , 10 ); // Enqueue theme compatibility styles. add_filter( 'woocommerce_enqueue_styles' , array ( __CLASS__ , 'enqueue_styles' ) ); // Register theme features. add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); add_theme_support( 'woocommerce' , array ( 'thumbnail_image_width' => 450, 'single_image_width' => 600, ) ); // Background color change. add_action( 'after_setup_theme' , array ( __CLASS__ , 'set_white_background' ), 10 ); } /** * Open the Twenty Twenty wrapper. */ public static function output_content_wrapper() { echo '<section id="primary" class="content-area">' ; echo '<main id="main" class="site-main">' ; } /** * Close the Twenty Twenty wrapper. */ public static function output_content_wrapper_end() { echo '</main>' ; echo '</section>' ; } /** * Set background color to white if it's default, otherwise don't touch it. */ public static function set_white_background() { $background = sanitize_hex_color_no_hash( get_theme_mod( 'background_color' ) ); $background_default = 'f5efe0' ; // Don't change user's choice of background color. if ( ! empty ( $background ) && $background !== $background_default ) { return ; } // In case default background is found, change it to white. set_theme_mod( 'background_color' , 'fff' ); } /** * Enqueue CSS for this theme. * * @param array $styles Array of registered styles. * @return array */ public static function enqueue_styles( $styles ) { unset( $styles [ 'woocommerce-general' ] ); $styles [ 'woocommerce-general' ] = array ( 'src' => str_replace ( array ( 'http:' , 'https:' ), '' , WC()->plugin_url() ) . '/assets/css/twenty-twenty.css' , 'deps' => '' , 'version' => Constants::get_constant( 'WC_VERSION' ), 'media' => 'all' , 'has_rtl' => true, ); return apply_filters( 'woocommerce_twenty_twenty_styles' , $styles ); } } |
Methods Methods
- enqueue_styles — Enqueue CSS for this theme.
- init — Theme init.
- output_content_wrapper — Open the Twenty Twenty wrapper.
- output_content_wrapper_end — Close the Twenty Twenty wrapper.
- set_white_background — Set background color to white if it's default, otherwise don't touch it.