PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.5.2
ShopBuilder – WooCommerce Builder For Elementor v2.5.2
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Controllers / ThemesSupport / Astra / WidgetsSupport.php

WidgetsSupport.php in ShopBuilder – WooCommerce Builder For Elementor 2.5.2, at app/Controllers/ThemesSupport/Astra/WidgetsSupport.php

367 lines 10.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Main ProductDescription class.
5 *
6 * @package RadiusTheme\SB
7 */
8
9 namespace RadiusTheme\SB\Controllers\ThemesSupport\Astra;
10
11 // Do not allow directly accessing this file.
12 use Rtwpvsp\Controllers\ShopPage;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit( 'This script cannot be accessed directly.' );
16 }
17
18 /**
19 * Product Description class
20 */
21 class WidgetsSupport {
22
23 /**
24 * The single instance of the class.
25 *
26 * @var object
27 */
28 protected static $instance = null;
29
30 /**
31 * The single instance of the class.
32 *
33 * @var object
34 */
35 private $widgets;
36
37 /**
38 * Construct function
39 */
40 private function __construct() {
41 }
42
43 /**
44 * Get class instance.
45 *
46 * @return object Instance.
47 */
48 public static function instance( $widgets ) {
49 if ( ! self::$instance ) {
50 self::$instance = new self();
51 }
52 self::$instance->widgets = $widgets;
53
54 return self::$instance;
55 }
56
57 /**
58 * @param $html
59 *
60 * @return string
61 */
62 public function astra_flash_sale_html_remove( $html ) {
63 return '';
64 }
65
66
67 /**
68 * Astra Wrapper
69 *
70 * @return void
71 */
72 public function astra_woo_shop_thumbnail_wrap_start() {
73 echo '<div class="astra-shop-thumbnail-wrap rtsb-image-wrapper">';
74 }
75
76 /**
77 * Product Loop content Modify.
78 *
79 * @return void
80 */
81 public function astra_product_loop() {
82 $controllers = $this->widgets->get_settings_for_display();
83
84 if ( ! apply_filters( 'astra_woo_shop_product_structure_override', false ) ) {
85 // Remove some hooks.
86 remove_action( 'woocommerce_before_shop_loop_item', 'astra_woo_shop_thumbnail_wrap_start', 6 );
87 remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
88 remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
89 remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
90 remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
91
92 // Adding some hooks.
93 add_action( 'woocommerce_before_shop_loop_item', [ $this, 'astra_woo_shop_thumbnail_wrap_start' ], 6 );
94 add_action( 'woocommerce_after_shop_loop_item', 'astra_woo_shop_thumbnail_wrap_end', 8 );
95 add_action( 'woocommerce_after_shop_loop_item', 'astra_woo_woocommerce_shop_product_content' );
96 add_action( 'astra_woo_shop_before_summary_wrap', [ $this->widgets, 'product_content_wrapper' ], 6 );
97 add_action( 'astra_woo_shop_after_summary_wrap', [ $this->widgets, 'div_close' ], 6 );
98
99 if ( empty( $controllers['show_flash_sale'] ) ) {
100 if ( ! defined( 'ASTRA_EXT_VER' ) || ( defined( 'ASTRA_EXT_VER' ) && ! \Astra_Ext_Extension::is_active( 'woocommerce' ) ) ) {
101 add_filter( 'astra_addon_shop_cards_buttons_html', [ $this, 'astra_flash_sale_html_remove' ] );
102 }
103 }
104 }
105 $this->widgets->apply_hooks_set_default();
106
107 // Variation Swatch fix
108 if ( class_exists( 'WooProductVariationSwatches' ) ) {
109 $swatches_position = rtwpvs()->get_option( 'archive_swatches_position' );
110 if ( 'before_title_and_price' == $swatches_position && class_exists( ShopPage::class ) ) {
111 remove_action(
112 'woocommerce_before_shop_loop_item_title',
113 [
114 ShopPage::class,
115 'archive_variation_swatches',
116 ],
117 35
118 );
119 add_action(
120 'astra_woo_shop_title_before',
121 [
122 ShopPage::class,
123 'archive_variation_swatches',
124 ],
125 35
126 );
127 }
128 }
129
130 // Remove Action Button.
131 add_filter( 'rtsb/module/wishlist/show_button', '__return_false' );
132 add_filter( 'rtsb/module/quick_view/show_button', '__return_false' );
133 add_filter( 'rtsb/module/compare/show_button', '__return_false' );
134 }
135
136 /**
137 * Product Content Reset.
138 *
139 * @return void
140 */
141 public function astra_product_loop_reset_default() {
142 $controllers = $this->widgets->get_settings_for_display();
143
144 if ( ! apply_filters( 'astra_woo_shop_product_structure_override', false ) ) {
145 // Remove Product Content Wrapper.
146 remove_action( 'astra_woo_shop_before_summary_wrap', [ $this->widgets, 'product_content_wrapper' ], 6 );
147 remove_action( 'astra_woo_shop_after_summary_wrap', [ $this->widgets, 'div_close' ], 6 );
148 if ( empty( $controllers['show_flash_sale'] ) ) {
149 if ( ! defined( 'ASTRA_EXT_VER' ) || ( defined( 'ASTRA_EXT_VER' ) && ! \Astra_Ext_Extension::is_active( 'woocommerce' ) ) ) {
150 remove_filter( 'astra_addon_shop_cards_buttons_html', [ $this, 'astra_flash_sale_html_remove' ] );
151 }
152 }
153 }
154 }
155
156 /**
157 * The function name comes from the widget base name "rtsb-products-archive". This is for theme support prefix with render.
158 *
159 * @return void
160 */
161 public function render_rtsb_products_archive() {
162 $this->astra_product_loop();
163 }
164
165 /**
166 *
167 * @return void
168 */
169 public function render_reset_rtsb_products_archive() {
170 $this->astra_product_loop_reset_default();
171 }
172 /**
173 * The function name comes from the widget base name "rtsb-products-archive". This is for theme support prefix with render.
174 *
175 * @return void
176 */
177 public function render_rtsb_product_rating() {
178 remove_filter( 'woocommerce_product_get_rating_html', [ \Astra_Woocommerce::get_instance(), 'rating_markup' ], 10 );
179 }
180 /**
181 * The function name comes from the widget base name "rtsb-products-archive". This is for theme support prefix with render.
182 *
183 * @return void
184 */
185 public function render_rtsb_upsells_product() {
186 $this->astra_product_loop();
187 }
188
189 /**
190 * Reset Hooks.
191 *
192 * @return void
193 */
194 public function render_reset_rtsb_upsells_product() {
195 $this->astra_product_loop_reset_default();
196 }
197
198 /**
199 * Related Product.
200 *
201 * @return void
202 */
203 public function render_rtsb_related_product() {
204 $this->astra_product_loop();
205 }
206
207 /**
208 * Related Product.
209 *
210 * @return void
211 */
212 public function render_reset_rtsb_related_product() {
213 $this->astra_product_loop_reset_default();
214 }
215
216 /**
217 * Cross Sell Product.
218 *
219 * @return void
220 */
221 public function render_rtsb_cross_sells() {
222 $this->astra_product_loop();
223 }
224
225 /**
226 * Cross Sell Product.
227 *
228 * @return void
229 */
230 public function render_reset_rtsb_cross_sells() {
231 $this->astra_product_loop_reset_default();
232 }
233
234 /**
235 * Cross Sell Product.
236 *
237 * @return void
238 */
239 public function render_rtsb_product_onsale() {
240 add_filter( 'woocommerce_sale_flash', [ \Astra_Woocommerce::get_instance(), 'get_sale_flash_markup' ], 10, 3 );
241 }
242 /**
243 * Cross Sell Product.
244 *
245 * @return void
246 */
247 public function render_rtsb_product_stock() {
248 remove_filter( 'woocommerce_get_stock_html', 'astra_woo_product_in_stock', 10, 2 );
249 }
250
251 /**
252 * The function name comes from the widget base name "rtsb-products-archive". This is for theme support prefix with widget_controls.
253 *
254 * @return void
255 */
256 public function widget_controls_rtsb_product_tabs() {
257 add_filter( 'rtsb/elements/elementor/widgets/controls/rtsb-product-tabs', [ $this, 'product_tabs_widget_controls_support' ] );
258 }
259
260 /**
261 * Widget Field.
262 *
263 * @return array
264 */
265 public function product_tabs_widget_controls_support( $fields ) {
266 $fields['nav_active_border_color']['selectors'] = array_merge(
267 $fields['nav_active_border_color']['selectors'],
268 [
269 '{{WRAPPER}} .woocommerce-tabs ul.tabs li.active:before' => 'background: {{VALUE}}',
270 ]
271 );
272 $fields['nav_active_hover_border_color']['selectors'] = array_merge(
273 $fields['nav_active_hover_border_color']['selectors'],
274 [
275 '{{WRAPPER}} .woocommerce-tabs ul.tabs li.active:hover:before' => 'background: {{VALUE}}',
276 ]
277 );
278
279 return $fields;
280 }
281
282 /**
283 * The function name comes from the widget base name "rtsb-products-archive". This is for theme support prefix with "widget_controls".
284 *
285 * @return void
286 */
287 public function widget_controls_rtsb_products_archive() {
288 add_filter( 'rtsb/elements/elementor/widgets/controls/rtsb-products-archive', [ $this, 'product_loop_widget_controls_support' ], 11 );
289 }
290
291 /**
292 * Widget Field.
293 *
294 * @return array
295 */
296 public function product_loop_widget_controls_support( $fields ) {
297 if ( $this->widgets->has_pagination ) {
298 $fields['prev_icon']['default'] = [
299 'value' => 'fas fa-long-arrow-alt-left',
300 'library' => 'fa-solid',
301 ];
302 $fields['next_icon']['default'] = [
303 'value' => 'fas fa-long-arrow-alt-right',
304 'library' => 'fa-solid',
305 ];
306 }
307 $astra_onsale_card = '{{WRAPPER}} .products .product .ast-onsale-card';
308 if ( ! empty( $fields['flash_sale_typography']['selector'] ) ) {
309 $fields['flash_sale_typography']['selector'] = $fields['flash_sale_typography']['selector'] . ',' . $astra_onsale_card;
310 }
311 if ( ! empty( $fields['product_flash_sale_color']['selectors'] ) ) {
312 $fields['product_flash_sale_color']['selectors'][ $astra_onsale_card ] = 'color: {{VALUE}};';
313 }
314 if ( ! empty( $fields['flash_sale_bg_color']['selectors'] ) ) {
315 $fields['flash_sale_bg_color']['selectors'][ $astra_onsale_card ] = 'background-color: {{VALUE}};';
316 }
317 if ( ! empty( $fields['flash_sale_badge_width']['selectors'] ) ) {
318 $fields['flash_sale_badge_width']['selectors'][ $astra_onsale_card ] = 'width: {{SIZE}}{{UNIT}}; text-align: center;';
319 }
320 if ( ! empty( $fields['flash_sale_badge_height']['selectors'] ) ) {
321 $fields['flash_sale_badge_height']['selectors'][ $astra_onsale_card ] = 'height: {{SIZE}}{{UNIT}};';
322 }
323 if ( ! empty( $fields['flash_sale_badge_border_radius']['selectors'] ) ) {
324 $fields['flash_sale_badge_border_radius']['selectors'][ $astra_onsale_card ] = 'border-radius: {{SIZE}}{{UNIT}};';
325 }
326 return $fields;
327 }
328
329 /**
330 * The function name comes from the widget base name "rtsb-products-archive". This is for theme support prefix with widget_controls.
331 *
332 * @return void
333 */
334 public function widget_controls_rtsb_related_product() {
335 add_filter( 'rtsb/elements/elementor/widgets/controls/rtsb-related-product', [ $this, 'widget_controls_flash_sale' ] );
336 }
337
338 /**
339 * @return void
340 */
341 public function widget_controls_rtsb_upsells_product() {
342 add_filter( 'rtsb/elements/elementor/widgets/controls/rtsb-upsells-product', [ $this, 'widget_controls_flash_sale' ] );
343 }
344 /**
345 * @return void
346 */
347 public function widget_controls_rtsb_cross_sells() {
348 add_filter( 'rtsb/elements/elementor/widgets/controls/rtsb-cross-sells', [ $this, 'widget_controls_flash_sale' ] );
349 }
350 /**
351 * Widget Field.
352 *
353 * @return array
354 */
355 public function widget_controls_flash_sale( $fields ) {
356 $selector = '{{WRAPPER}} .products .product .ast-onsale-card';
357 $fields['flash_sale_typography']['selector'] = $selector;
358 $fields['product_flash_sale_color']['selectors'][ $selector ] = 'color: {{VALUE}};';
359 $fields['flash_sale_bg_color']['selectors'][ $selector ] = 'background-color: {{VALUE}};';
360 $fields['flash_sale_badge_width']['selectors'][ $selector ] = 'width: {{SIZE}}{{UNIT}};display:flex; justify-content: center;';
361 $fields['flash_sale_badge_height']['selectors'][ $selector ] = 'height: {{SIZE}}{{UNIT}};align-items:center;';
362 $fields['flash_sale_badge_border_radius']['selectors'][ $selector ] = 'border-radius: {{SIZE}}{{UNIT}};';
363
364 return $fields;
365 }
366 }
367