class-wc-twenty-eleven.php
5 years ago
class-wc-twenty-fifteen.php
5 years ago
class-wc-twenty-fourteen.php
5 years ago
class-wc-twenty-nineteen.php
5 years ago
class-wc-twenty-seventeen.php
5 years ago
class-wc-twenty-sixteen.php
5 years ago
class-wc-twenty-ten.php
5 years ago
class-wc-twenty-thirteen.php
5 years ago
class-wc-twenty-twelve.php
2 years ago
class-wc-twenty-twenty-one.php
5 years ago
class-wc-twenty-twenty-three.php
3 years ago
class-wc-twenty-twenty-two.php
4 years ago
class-wc-twenty-twenty.php
5 years ago
class-wc-twenty-nineteen.php
133 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Twenty Nineteen support. |
| 4 | * |
| 5 | * @since 3.5.X |
| 6 | * @package WooCommerce\Classes |
| 7 | */ |
| 8 | |
| 9 | use Automattic\Jetpack\Constants; |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; |
| 12 | |
| 13 | /** |
| 14 | * WC_Twenty_Nineteen class. |
| 15 | */ |
| 16 | class WC_Twenty_Nineteen { |
| 17 | |
| 18 | /** |
| 19 | * Theme init. |
| 20 | */ |
| 21 | public static function init() { |
| 22 | |
| 23 | // Change WooCommerce wrappers. |
| 24 | remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 ); |
| 25 | remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 ); |
| 26 | |
| 27 | add_action( 'woocommerce_before_main_content', array( __CLASS__, 'output_content_wrapper' ), 10 ); |
| 28 | add_action( 'woocommerce_after_main_content', array( __CLASS__, 'output_content_wrapper_end' ), 10 ); |
| 29 | |
| 30 | // This theme doesn't have a traditional sidebar. |
| 31 | remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 ); |
| 32 | |
| 33 | // Enqueue theme compatibility styles. |
| 34 | add_filter( 'woocommerce_enqueue_styles', array( __CLASS__, 'enqueue_styles' ) ); |
| 35 | |
| 36 | // Register theme features. |
| 37 | add_theme_support( 'wc-product-gallery-zoom' ); |
| 38 | add_theme_support( 'wc-product-gallery-lightbox' ); |
| 39 | add_theme_support( 'wc-product-gallery-slider' ); |
| 40 | add_theme_support( |
| 41 | 'woocommerce', |
| 42 | array( |
| 43 | 'thumbnail_image_width' => 300, |
| 44 | 'single_image_width' => 450, |
| 45 | ) |
| 46 | ); |
| 47 | |
| 48 | // Tweak Twenty Nineteen features. |
| 49 | add_action( 'wp', array( __CLASS__, 'tweak_theme_features' ) ); |
| 50 | |
| 51 | // Color scheme CSS. |
| 52 | add_filter( 'twentynineteen_custom_colors_css', array( __CLASS__, 'custom_colors_css' ), 10, 3 ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Open the Twenty Nineteen wrapper. |
| 57 | */ |
| 58 | public static function output_content_wrapper() { |
| 59 | echo '<section id="primary" class="content-area">'; |
| 60 | echo '<main id="main" class="site-main">'; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Close the Twenty Nineteen wrapper. |
| 65 | */ |
| 66 | public static function output_content_wrapper_end() { |
| 67 | echo '</main>'; |
| 68 | echo '</section>'; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Enqueue CSS for this theme. |
| 73 | * |
| 74 | * @param array $styles Array of registered styles. |
| 75 | * @return array |
| 76 | */ |
| 77 | public static function enqueue_styles( $styles ) { |
| 78 | unset( $styles['woocommerce-general'] ); |
| 79 | |
| 80 | $styles['woocommerce-general'] = array( |
| 81 | 'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/twenty-nineteen.css', |
| 82 | 'deps' => '', |
| 83 | 'version' => Constants::get_constant( 'WC_VERSION' ), |
| 84 | 'media' => 'all', |
| 85 | 'has_rtl' => true, |
| 86 | ); |
| 87 | |
| 88 | return apply_filters( 'woocommerce_twenty_nineteen_styles', $styles ); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Tweak Twenty Nineteen features. |
| 93 | */ |
| 94 | public static function tweak_theme_features() { |
| 95 | if ( is_woocommerce() ) { |
| 96 | add_filter( 'twentynineteen_can_show_post_thumbnail', '__return_false' ); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Filters Twenty Nineteen custom colors CSS. |
| 102 | * |
| 103 | * @param string $css Base theme colors CSS. |
| 104 | * @param int $primary_color The user's selected color hue. |
| 105 | * @param string $saturation Filtered theme color saturation level. |
| 106 | */ |
| 107 | public static function custom_colors_css( $css, $primary_color, $saturation ) { |
| 108 | if ( function_exists( 'register_block_type' ) && is_admin() ) { |
| 109 | return $css; |
| 110 | } |
| 111 | |
| 112 | $lightness = absint( apply_filters( 'twentynineteen_custom_colors_lightness', 33 ) ); |
| 113 | $lightness = $lightness . '%'; |
| 114 | |
| 115 | $css .= ' |
| 116 | .onsale, |
| 117 | .woocommerce-info, |
| 118 | .woocommerce-store-notice { |
| 119 | background-color: hsl( ' . $primary_color . ', ' . $saturation . ', ' . $lightness . ' ); |
| 120 | } |
| 121 | |
| 122 | .woocommerce-tabs ul li.active a { |
| 123 | color: hsl( ' . $primary_color . ', ' . $saturation . ', ' . $lightness . ' ); |
| 124 | box-shadow: 0 2px 0 hsl( ' . $primary_color . ', ' . $saturation . ', ' . $lightness . ' ); |
| 125 | } |
| 126 | '; |
| 127 | |
| 128 | return $css; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | WC_Twenty_Nineteen::init(); |
| 133 |