Brak opisu

class-wc-twenty-nineteen.php 3.6KB

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