PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/themes/storefront/inc/woocommerce/class-storefront-woocommerce.php

https://gitlab.com/leobelizquierdo/cabotsubmitter-wordpress
PHP | 339 lines | 191 code | 39 blank | 109 comment | 23 complexity | 442caa90096b30a1adda584febdbc4ed MD5 | raw file
  1. <?php
  2. /**
  3. * Storefront WooCommerce Class
  4. *
  5. * @package storefront
  6. * @author WooThemes
  7. * @since 2.0.0
  8. */
  9. if ( ! defined( 'ABSPATH' ) ) {
  10. exit;
  11. }
  12. if ( ! class_exists( 'Storefront_WooCommerce' ) ) :
  13. /**
  14. * The Storefront WooCommerce Integration class
  15. */
  16. class Storefront_WooCommerce {
  17. /**
  18. * Setup class.
  19. *
  20. * @since 1.0
  21. */
  22. public function __construct() {
  23. add_filter( 'loop_shop_columns', array( $this, 'loop_columns' ) );
  24. add_filter( 'body_class', array( $this, 'woocommerce_body_class' ) );
  25. add_action( 'wp_enqueue_scripts', array( $this, 'woocommerce_scripts' ), 20 );
  26. add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
  27. add_filter( 'woocommerce_output_related_products_args', array( $this, 'related_products_args' ) );
  28. add_filter( 'woocommerce_product_thumbnails_columns', array( $this, 'thumbnail_columns' ) );
  29. add_filter( 'loop_shop_per_page', array( $this, 'products_per_page' ) );
  30. if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.5', '<' ) ) {
  31. add_action( 'wp_footer', array( $this, 'star_rating_script' ) );
  32. }
  33. // Integrations.
  34. add_action( 'wp_enqueue_scripts', array( $this, 'woocommerce_integrations_scripts' ) );
  35. add_action( 'wp_enqueue_scripts', array( $this, 'add_integrations_customizer_css' ) );
  36. }
  37. /**
  38. * Default loop columns on product archives
  39. *
  40. * @return integer products per row
  41. * @since 1.0.0
  42. */
  43. public function loop_columns() {
  44. return apply_filters( 'storefront_loop_columns', 3 ); // 3 products per row
  45. }
  46. /**
  47. * Add 'woocommerce-active' class to the body tag
  48. *
  49. * @param array $classes css classes applied to the body tag.
  50. * @return array $classes modified to include 'woocommerce-active' class
  51. */
  52. public function woocommerce_body_class( $classes ) {
  53. if ( is_woocommerce_activated() ) {
  54. $classes[] = 'woocommerce-active';
  55. }
  56. return $classes;
  57. }
  58. /**
  59. * WooCommerce specific scripts & stylesheets
  60. *
  61. * @since 1.0.0
  62. */
  63. public function woocommerce_scripts() {
  64. global $storefront_version;
  65. wp_enqueue_style( 'storefront-woocommerce-style', get_template_directory_uri() . '/assets/sass/woocommerce/woocommerce.css', $storefront_version );
  66. wp_style_add_data( 'storefront-woocommerce-style', 'rtl', 'replace' );
  67. wp_register_script( 'storefront-sticky-payment', get_template_directory_uri() . '/assets/js/woocommerce/checkout.min.js', 'jquery', $storefront_version, true );
  68. if ( is_checkout() ) {
  69. wp_enqueue_script( 'storefront-sticky-payment' );
  70. }
  71. }
  72. /**
  73. * Star rating backwards compatibility script (WooCommerce <2.5).
  74. *
  75. * @since 1.6.0
  76. */
  77. public function star_rating_script() {
  78. if ( wp_script_is( 'jquery', 'done' ) && is_product() ) {
  79. ?>
  80. <script type="text/javascript">
  81. jQuery( function( $ ) {
  82. $( 'body' ).on( 'click', '#respond p.stars a', function() {
  83. var $container = $( this ).closest( '.stars' );
  84. $container.addClass( 'selected' );
  85. });
  86. });
  87. </script>
  88. <?php
  89. }
  90. }
  91. /**
  92. * Related Products Args
  93. *
  94. * @param array $args related products args.
  95. * @since 1.0.0
  96. * @return array $args related products args
  97. */
  98. public function related_products_args( $args ) {
  99. $args = apply_filters( 'storefront_related_products_args', array(
  100. 'posts_per_page' => 3,
  101. 'columns' => 3,
  102. ) );
  103. return $args;
  104. }
  105. /**
  106. * Product gallery thumnail columns
  107. *
  108. * @return integer number of columns
  109. * @since 1.0.0
  110. */
  111. public function thumbnail_columns() {
  112. return intval( apply_filters( 'storefront_product_thumbnail_columns', 4 ) );
  113. }
  114. /**
  115. * Products per page
  116. *
  117. * @return integer number of products
  118. * @since 1.0.0
  119. */
  120. public function products_per_page() {
  121. return intval( apply_filters( 'storefront_products_per_page', 12 ) );
  122. }
  123. /**
  124. * Query WooCommerce Extension Activation.
  125. *
  126. * @param string $extension Extension class name.
  127. * @return boolean
  128. */
  129. public function is_woocommerce_extension_activated( $extension = 'WC_Bookings' ) {
  130. return class_exists( $extension ) ? true : false;
  131. }
  132. /**
  133. * Integration Styles & Scripts
  134. *
  135. * @return void
  136. */
  137. public function woocommerce_integrations_scripts() {
  138. /**
  139. * Bookings
  140. */
  141. if ( $this->is_woocommerce_extension_activated( 'WC_Bookings' ) ) {
  142. wp_enqueue_style( 'storefront-woocommerce-bookings-style', get_template_directory_uri() . '/assets/sass/woocommerce/bookings.css', 'storefront-woocommerce-style' );
  143. wp_style_add_data( 'storefront-woocommerce-bookings-style', 'rtl', 'replace' );
  144. }
  145. /**
  146. * Brands
  147. */
  148. if ( $this->is_woocommerce_extension_activated( 'WC_Brands' ) ) {
  149. wp_enqueue_style( 'storefront-woocommerce-brands-style', get_template_directory_uri() . '/assets/sass/woocommerce/brands.css', 'storefront-woocommerce-style' );
  150. wp_style_add_data( 'storefront-woocommerce-brands-style', 'rtl', 'replace' );
  151. }
  152. /**
  153. * Wishlists
  154. */
  155. if ( $this->is_woocommerce_extension_activated( 'WC_Wishlists_Wishlist' ) ) {
  156. wp_enqueue_style( 'storefront-woocommerce-wishlists-style', get_template_directory_uri() . '/assets/sass/woocommerce/wishlists.css', 'storefront-woocommerce-style' );
  157. wp_style_add_data( 'storefront-woocommerce-wishlists-style', 'rtl', 'replace' );
  158. }
  159. /**
  160. * AJAX Layered Nav
  161. */
  162. if ( $this->is_woocommerce_extension_activated( 'SOD_Widget_Ajax_Layered_Nav' ) ) {
  163. wp_enqueue_style( 'storefront-woocommerce-ajax-layered-nav-style', get_template_directory_uri() . '/assets/sass/woocommerce/ajax-layered-nav.css', 'storefront-woocommerce-style' );
  164. wp_style_add_data( 'storefront-woocommerce-ajax-layered-nav-style', 'rtl', 'replace' );
  165. }
  166. /**
  167. * Variation Swatches
  168. */
  169. if ( $this->is_woocommerce_extension_activated( 'WC_SwatchesPlugin' ) ) {
  170. wp_enqueue_style( 'storefront-woocommerce-variation-swatches-style', get_template_directory_uri() . '/assets/sass/woocommerce/variation-swatches.css', 'storefront-woocommerce-style' );
  171. wp_style_add_data( 'storefront-woocommerce-variation-swatches-style', 'rtl', 'replace' );
  172. }
  173. /**
  174. * Composite Products
  175. */
  176. if ( $this->is_woocommerce_extension_activated( 'WC_Composite_Products' ) ) {
  177. wp_enqueue_style( 'storefront-woocommerce-composite-products-style', get_template_directory_uri() . '/assets/sass/woocommerce/composite-products.css', 'storefront-woocommerce-style' );
  178. wp_style_add_data( 'storefront-woocommerce-composite-products-style', 'rtl', 'replace' );
  179. }
  180. /**
  181. * WooCommerce Photography
  182. */
  183. if ( $this->is_woocommerce_extension_activated( 'WC_Photography' ) ) {
  184. wp_enqueue_style( 'storefront-woocommerce-photography-style', get_template_directory_uri() . '/assets/sass/woocommerce/photography.css', 'storefront-woocommerce-style' );
  185. wp_style_add_data( 'storefront-woocommerce-photography-style', 'rtl', 'replace' );
  186. }
  187. /**
  188. * Product Reviews Pro
  189. */
  190. if ( $this->is_woocommerce_extension_activated( 'WC_Product_Reviews_Pro' ) ) {
  191. wp_enqueue_style( 'storefront-woocommerce-product-reviews-pro-style', get_template_directory_uri() . '/assets/sass/woocommerce/product-reviews-pro.css', 'storefront-woocommerce-style' );
  192. wp_style_add_data( 'storefront-woocommerce-product-reviews-pro-style', 'rtl', 'replace' );
  193. }
  194. /**
  195. * WooCommerce Smart Coupons
  196. */
  197. if ( $this->is_woocommerce_extension_activated( 'WC_Smart_Coupons' ) ) {
  198. wp_enqueue_style( 'storefront-woocommerce-smart-coupons-style', get_template_directory_uri() . '/assets/sass/woocommerce/smart-coupons.css', 'storefront-woocommerce-style' );
  199. wp_style_add_data( 'storefront-woocommerce-smart-coupons-style', 'rtl', 'replace' );
  200. }
  201. /**
  202. * WooCommerce Deposits
  203. */
  204. if ( $this->is_woocommerce_extension_activated( 'WC_Deposits' ) ) {
  205. wp_enqueue_style( 'storefront-woocommerce-deposits-style', get_template_directory_uri() . '/assets/sass/woocommerce/deposits.css', 'storefront-woocommerce-style' );
  206. wp_style_add_data( 'storefront-woocommerce-deposits-style', 'rtl', 'replace' );
  207. }
  208. /**
  209. * WooCommerce Product Bundles
  210. */
  211. if ( $this->is_woocommerce_extension_activated( 'WC_Bundles' ) ) {
  212. wp_enqueue_style( 'storefront-woocommerce-bundles-style', get_template_directory_uri() . '/assets/sass/woocommerce/bundles.css', 'storefront-woocommerce-style' );
  213. wp_style_add_data( 'storefront-woocommerce-bundles-style', 'rtl', 'replace' );
  214. }
  215. /**
  216. * WooCommerce Multiple Shipping Addresses
  217. */
  218. if ( $this->is_woocommerce_extension_activated( 'WC_Ship_Multiple' ) ) {
  219. wp_enqueue_style( 'storefront-woocommerce-sma-style', get_template_directory_uri() . '/assets/sass/woocommerce/ship-multiple-addresses.css', 'storefront-woocommerce-style' );
  220. wp_style_add_data( 'storefront-woocommerce-sma-style', 'rtl', 'replace' );
  221. }
  222. }
  223. /**
  224. * Add CSS in <head> for integration styles handled by the theme customizer
  225. *
  226. * @since 1.0
  227. */
  228. public function add_integrations_customizer_css() {
  229. $accent_color = get_theme_mod( 'storefront_accent_color', apply_filters( 'storefront_default_accent_color', '#FFA107' ) );
  230. $header_text_color = get_theme_mod( 'storefront_header_text_color', apply_filters( 'storefront_default_header_text_color', '#9aa0a7' ) );
  231. $header_background_color = get_theme_mod( 'storefront_header_background_color', apply_filters( 'storefront_default_header_background_color', '#2c2d33' ) );
  232. $text_color = get_theme_mod( 'storefront_text_color', apply_filters( 'storefront_default_text_color', '#60646c' ) );
  233. $button_background_color = get_theme_mod( 'storefront_button_background_color', apply_filters( 'storefront_default_button_background_color', '#60646c' ) );
  234. $button_text_color = get_theme_mod( 'storefront_button_text_color', apply_filters( 'storefront_default_button_text_color', '#ffffff' ) );
  235. $woocommerce_style = '';
  236. if ( $this->is_woocommerce_extension_activated( 'WC_Bookings' ) ) {
  237. $woocommerce_style .= '
  238. #wc-bookings-booking-form .wc-bookings-date-picker .ui-datepicker td.bookable a,
  239. #wc-bookings-booking-form .wc-bookings-date-picker .ui-datepicker td.bookable a:hover,
  240. #wc-bookings-booking-form .block-picker li a:hover,
  241. #wc-bookings-booking-form .block-picker li a.selected {
  242. background-color: ' . $accent_color . ' !important;
  243. }
  244. #wc-bookings-booking-form .wc-bookings-date-picker .ui-datepicker td.ui-state-disabled .ui-state-default,
  245. #wc-bookings-booking-form .wc-bookings-date-picker .ui-datepicker th {
  246. color:' . $text_color . ';
  247. }
  248. #wc-bookings-booking-form .wc-bookings-date-picker .ui-datepicker-header {
  249. background-color: ' . $header_background_color . ';
  250. color: ' . $header_text_color . ';
  251. }';
  252. }
  253. if ( $this->is_woocommerce_extension_activated( 'WC_Product_Reviews_Pro' ) ) {
  254. $woocommerce_style .= '
  255. .woocommerce #reviews .product-rating .product-rating-details table td.rating-graph .bar,
  256. .woocommerce-page #reviews .product-rating .product-rating-details table td.rating-graph .bar {
  257. background-color: ' . $text_color . ' !important;
  258. }
  259. .woocommerce #reviews .contribution-actions .feedback,
  260. .woocommerce-page #reviews .contribution-actions .feedback,
  261. .star-rating-selector:not(:checked) label.checkbox {
  262. color: ' . $text_color . ';
  263. }
  264. .woocommerce #reviews #comments ol.commentlist li .contribution-actions a,
  265. .woocommerce-page #reviews #comments ol.commentlist li .contribution-actions a,
  266. .star-rating-selector:not(:checked) input:checked ~ label.checkbox,
  267. .star-rating-selector:not(:checked) label.checkbox:hover ~ label.checkbox,
  268. .star-rating-selector:not(:checked) label.checkbox:hover,
  269. .woocommerce #reviews #comments ol.commentlist li .contribution-actions a,
  270. .woocommerce-page #reviews #comments ol.commentlist li .contribution-actions a,
  271. .woocommerce #reviews .form-contribution .attachment-type:not(:checked) label.checkbox:before,
  272. .woocommerce-page #reviews .form-contribution .attachment-type:not(:checked) label.checkbox:before {
  273. color: ' . $accent_color . ' !important;
  274. }';
  275. }
  276. if ( $this->is_woocommerce_extension_activated( 'WC_Smart_Coupons' ) ) {
  277. $woocommerce_style .= '
  278. .coupon-container {
  279. background-color: ' . $button_background_color . ' !important;
  280. }
  281. .coupon-content {
  282. border-color: ' . $button_text_color . ' !important;
  283. color: ' . $button_text_color . ';
  284. }
  285. .sd-buttons-transparent.woocommerce .coupon-content,
  286. .sd-buttons-transparent.woocommerce-page .coupon-content {
  287. border-color: ' . $button_background_color . ' !important;
  288. }';
  289. }
  290. wp_add_inline_style( 'storefront-style', $woocommerce_style );
  291. }
  292. }
  293. endif;
  294. return new Storefront_WooCommerce();