Nessuna descrizione

class-wc-twenty-twenty.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * Twenty Twenty support.
  4. *
  5. * @since 3.8.1
  6. * @package WooCommerce\Classes
  7. */
  8. use Automattic\Jetpack\Constants;
  9. defined( 'ABSPATH' ) || exit;
  10. /**
  11. * WC_Twenty_Twenty class.
  12. */
  13. class WC_Twenty_Twenty {
  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' => 450,
  35. 'single_image_width' => 600,
  36. )
  37. );
  38. // Background color change.
  39. add_action( 'after_setup_theme', array( __CLASS__, 'set_white_background' ), 10 );
  40. }
  41. /**
  42. * Open the Twenty Twenty wrapper.
  43. */
  44. public static function output_content_wrapper() {
  45. echo '<section id="primary" class="content-area">';
  46. echo '<main id="main" class="site-main">';
  47. }
  48. /**
  49. * Close the Twenty Twenty wrapper.
  50. */
  51. public static function output_content_wrapper_end() {
  52. echo '</main>';
  53. echo '</section>';
  54. }
  55. /**
  56. * Set background color to white if it's default, otherwise don't touch it.
  57. */
  58. public static function set_white_background() {
  59. $background = sanitize_hex_color_no_hash( get_theme_mod( 'background_color' ) );
  60. $background_default = 'f5efe0';
  61. // Don't change user's choice of background color.
  62. if ( ! empty( $background ) && $background !== $background_default ) {
  63. return;
  64. }
  65. // In case default background is found, change it to white.
  66. set_theme_mod( 'background_color', 'fff' );
  67. }
  68. /**
  69. * Enqueue CSS for this theme.
  70. *
  71. * @param array $styles Array of registered styles.
  72. * @return array
  73. */
  74. public static function enqueue_styles( $styles ) {
  75. unset( $styles['woocommerce-general'] );
  76. $styles['woocommerce-general'] = array(
  77. 'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/twenty-twenty.css',
  78. 'deps' => '',
  79. 'version' => Constants::get_constant( 'WC_VERSION' ),
  80. 'media' => 'all',
  81. 'has_rtl' => true,
  82. );
  83. return apply_filters( 'woocommerce_twenty_twenty_styles', $styles );
  84. }
  85. }
  86. WC_Twenty_Twenty::init();