PluginProbe
Themify Builder / trunk
Themify Builder vtrunk
7.8.1 7.8.0 7.7.9 7.7.8 7.7.7 7.7.6 7.7.5 7.7.4 7.7.3 7.7.2 trunk 7.6.0 7.6.1 7.6.2 7.6.3 7.6.4 7.6.5 7.6.6 7.6.7 7.6.8 7.6.9 7.7.0 7.7.1
themify-builder / themify / plugin-compat / woocommerce.php

woocommerce.php in Themify Builder trunk, at themify/plugin-compat/woocommerce.php

204 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Themify Compatibility Code
5 *
6 * @package Themify
7 */
8
9 /**
10 * WooCommerce
11 *
12 * @link https://woocommerce.com/
13 */
14 class Themify_Compat_woocommerce {
15
16
17 static function init() {
18 add_action( 'template_redirect', array( __CLASS__, 'template_redirect' ) );
19 add_action( 'woocommerce_init', array( __CLASS__, 'woocommerce_init' ) );
20 }
21
22 public static function woocommerce_init() {
23 remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper' );
24 remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end' );
25 remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar' );
26 add_action( 'woocommerce_before_main_content', 'themify_before_wrap_content', 1 );
27 add_action( 'woocommerce_after_main_content', 'themify_after_wrap_content', 100 );
28 if ( current_theme_supports( 'themify-sticky-buy' ) ) {
29 add_action( 'template_redirect', 'themify_wc_sticky_buy', 12 );
30 }
31 if ( current_theme_supports( 'themify-wc-accordion-tabs' ) ) {
32 $tabType = themify_get( 'setting-product_tabs_layout', 'tab', true );
33 if ( 'none' === $tabType ) {
34 remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
35 } elseif ( $tabType === 'accordion' ) {
36 add_filter( 'wc_get_template', 'themify_wc_accordion_tabs', 10, 5 );
37 }
38 }
39 add_filter( 'body_class', array( __CLASS__, 'single_product_body_class' ) );
40 add_action( 'woocommerce_before_shop_loop_item', 'themify_post_edit_link' );
41 }
42
43 /**
44 * Fix video display in Focus Mode
45 *
46 * @access public
47 */
48 public static function template_redirect() {
49 global $themify;
50 if ( $themify->page_title === 'yes' && themify_is_shop() ) {
51 add_filter( 'woocommerce_show_page_title', '__return_false', 100 );
52 }
53 if ( is_product() ) {
54 add_filter( 'woocommerce_post_class', array( __CLASS__, 'woocommerce_post_class' ), 10, 2 );
55 }
56 }
57
58 /**
59 * Add Product taxonomy as Body Class to Single Product Page
60 *
61 * @access public
62 */
63 public static function single_product_body_class( $classes ) {
64 $classes[] = 'woocommerce-js';
65 $index = array_search( 'woocommerce-no-js', $classes, true );
66 if ( $index !== false ) {
67 unset( $classes[ $index ] );
68 }
69 if ( is_singular( 'product' ) ) {
70 $current_product = wc_get_product();
71 $id = $current_product->get_id();
72 $tax = array( 'product_cat', 'product_tag' );
73 foreach ( $tax as $v ) {
74 $custom_terms = get_the_terms( $id, $v );
75 if ( $custom_terms ) {
76 foreach ( $custom_terms as $custom_term ) {
77 $classes[] = $v . '_' . $custom_term->slug;
78 }
79 }
80 }
81 }
82 return $classes;
83 }
84
85 public static function woocommerce_post_class( $classes, $product ) {
86 if ( $product->get_id() === get_queried_object_id() ) {
87 $classes[] = 'tf_clearfix';
88 }
89
90 return $classes;
91 }
92 }
93
94 if ( ! function_exists( 'themify_wc_accordion_tabs' ) ) :
95 function themify_wc_accordion_tabs( $located, $template_name, $args, $template_path, $default_path ) {
96 if ( 'single-product/tabs/tabs.php' == $template_name ) {
97 remove_filter( 'wc_get_template', 'themify_wc_accordion_tabs', 10 );
98 return THEMIFY_DIR . '/includes/wc-accordion-tabs.php';
99 }
100 return $located;
101 }
102 endif;
103
104 if ( ! function_exists( 'themify_wc_sticky_buy' ) ) :
105 function themify_wc_sticky_buy() {
106 if ( is_product() && ! ( class_exists( 'Themify_Builder_Model', false ) && Themify_Builder_Model::is_front_builder_activate() ) && ! themify_check( 'setting-st_add_cart', true ) ) {
107 add_action( 'woocommerce_before_add_to_cart_form', 'themify_sticky_buy_observer_start' );
108 add_action( 'woocommerce_after_add_to_cart_form', 'themify_sticky_buy_observer_end' );
109 }
110 }
111 endif;
112
113
114 if ( ! function_exists( 'themify_sticky_buy_observer_start' ) ) :
115 function themify_sticky_buy_observer_start() {
116 ob_start();
117 echo '<div id="tf_sticky_form_wrap" data-lazy="1">';
118 return ob_end_flush();
119 }
120 endif;
121
122 if ( ! function_exists( 'themify_sticky_buy_observer_end' ) ) :
123 function themify_sticky_buy_observer_end() {
124 ob_start();
125 echo '</div>';
126 return ob_end_flush();
127 }
128 endif;
129
130 if ( ! function_exists( 'themify_before_wrap_content' ) ) :
131 function themify_before_wrap_content() {
132 if ( function_exists( 'themify_before_shop_content' ) && current_action() === 'woocommerce_before_main_content' ) {
133 return;
134 }
135 ?>
136 <!-- layout -->
137 <div id="layout" class="pagewidth tf_box tf_clearfix">
138 <?php
139 themify_content_before(); // Hook
140 ?>
141 <!-- content -->
142 <main id="content" class="tf_box tf_clearfix">
143 <?php
144 themify_content_start(); // Hook
145 }
146 endif;
147
148 if ( ! function_exists( 'themify_after_wrap_content' ) ) :
149 function themify_after_wrap_content() {
150 if ( function_exists( 'themify_after_shop_content' ) && current_action() === 'woocommerce_after_main_content' ) {
151 return;
152 }
153 themify_content_end(); // Hook
154 ?>
155 </main>
156 <!-- /#content -->
157 <?php
158 themify_content_after(); // Hook
159 themify_get_sidebar();
160 ?>
161 </div><!-- /#layout -->
162 <?php
163 }
164 endif;
165
166 if (! function_exists('themify_wc_get_script_handle')) :
167 /**
168 * Get the correct WooCommerce script handle depending on WC version.
169 *
170 * @param string $handle The original (legacy) handle name, e.g. 'js-cookie' or 'jquery-blockui'.
171 * @return string The correct handle name for the current WooCommerce version.
172 */
173 function themify_wc_get_script_handle($handle)
174 {
175 // Ensure WooCommerce is active.
176 if (! defined('WC_VERSION')) {
177 return $handle;
178 }
179
180 $version = WC_VERSION;
181 $is_new = version_compare($version, '10.3.0', '>=');
182
183 // Map of renamed script handles (WooCommerce 10.3.0+)
184 $renamed_scripts = [
185 'js-cookie' => 'wc-js-cookie',
186 'jquery-blockui' => 'wc-jquery-blockui',
187 'flexslider' => 'wc-flexslider',
188 'photoswipe-ui-default' => 'wc-photoswipe-ui-default',
189 'zoom' => 'wc-zoom',
190 ];
191
192 // Normalize both prefixed and unprefixed handles.
193 foreach ($renamed_scripts as $old => $new) {
194 if ($handle === $old || $handle === $new) {
195 return $is_new ? $new : $old;
196 }
197 }
198
199 // Return original handle if no match found.
200 return $handle;
201 }
202
203 endif;
204