PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.0.2
ShopBuilder – WooCommerce Builder For Elementor v2.0.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 / Elementor / Widgets / Single / ProductImages.php

ProductImages.php in ShopBuilder – WooCommerce Builder For Elementor 2.0.2, at app/Elementor/Widgets/Single/ProductImages.php

218 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Main ProductImages class.
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Elementor\Widgets\Single;
9
10 use RadiusTheme\SB\Helpers\BuilderFns;
11 use RadiusTheme\SB\Helpers\ElementorDataMap;
12 use RadiusTheme\SB\Helpers\Fns;
13 use RadiusTheme\SB\Abstracts\ElementorWidgetBase;
14 use RadiusTheme\SB\Elementor\Widgets\Controls\ProductImagesSettings;
15
16 // Do not allow directly accessing this file.
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit( 'This script cannot be accessed directly.' );
19 }
20
21 /**
22 * Product Images class
23 */
24 class ProductImages extends ElementorWidgetBase {
25 /**
26 * Construct function
27 *
28 * @param array $data default array.
29 * @param mixed $args default arg.
30 */
31 public function __construct( $data = [], $args = null ) {
32 $this->rtsb_name = esc_html__( 'Product Images', 'shopbuilder' );
33 $this->rtsb_base = 'rtsb-product-image';
34 parent::__construct( $data, $args );
35 add_action( 'wp_footer', 'woocommerce_photoswipe' );
36 $this->the_hooks();
37 }
38
39 /**
40 * Widget Field
41 *
42 * @return array
43 */
44 public function widget_fields() {
45 return ProductImagesSettings::widget_fields( $this );
46 }
47
48 /**
49 * Widget Field.
50 *
51 * @return void
52 */
53 public function editor_scripts() {
54 ?>
55 <script>
56 /*
57 * Initialize all galleries on page.
58 */
59 jQuery('.woocommerce-product-gallery').each(function () {
60 const that = this;
61 jQuery(this).trigger('wc-product-gallery-before-init', [this, wc_single_product_params]);
62 setTimeout(function () {
63 jQuery(that).wc_product_gallery(wc_single_product_params);
64 }, 1000);
65
66 jQuery(this).trigger('wc-product-gallery-after-init', [this, wc_single_product_params]);
67 });
68 <?php if ( function_exists( 'rtwpvg' ) ) { ?>
69 setTimeout(function () {
70 jQuery('.rtsb-product-images .rtwpvg-wrapper').rtWpVGallery();
71 }, 1000);
72 <?php } ?>
73
74 jQuery(document).ready(function ($) {
75 setTimeout(function () {
76 const zoomIcon = $('.rtsb-product-images').attr('data-zoom-icon');
77 if (!zoomIcon) {
78 $('.rtsb-product-images')
79 .find('.woocommerce-product-gallery__trigger,.rtwpvg-trigger')
80 .remove();
81 }
82 $('.rtsb-product-images')
83 .find('.woocommerce-product-gallery__trigger,.rtwpvg-trigger')
84 .html(zoomIcon);
85 }, 50);
86 });
87 </script>
88 <?php
89 }
90
91 /**
92 * Widget Field.
93 *
94 * @param array $control Control.
95 *
96 * @return void
97 */
98 public function the_hooks( $control = [] ) {
99 if ( empty( $control ) ) {
100 return;
101 }
102 add_filter(
103 'woocommerce_product_thumbnails_columns',
104 function ( $col ) {
105 $col = 0;
106
107 return $col;
108 }
109 );
110 if ( empty( $control['show_zoom'] ) ) {
111 add_filter( 'rtwpvg_trigger_icon', '__return_false' );
112 }
113 if ( empty( $control['show_thumbnails'] ) ) {
114 add_filter( 'rtwpvg_show_product_thumbnail_slider', '__return_false' );
115 remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
116 }
117
118 add_filter( 'rtwpvg_thumbnail_position', [ $this, 'thumbnail_position' ], 50 );
119 add_filter( 'rtwpvg_thumbnails_columns', [ $this, 'thumbnails_columns' ] );
120 add_filter( 'rtwpvg_sm_thumbnails_columns', [ $this, 'thumbnails_columns_sm' ] );
121 add_filter( 'rtwpvg_xs_thumbnails_columns', [ $this, 'thumbnails_columns_xs' ] );
122 // add_filter( 'rtwpvg_image_classes', [ $this, 'rtwpvg_image_classes' ], 15 );
123
124 }
125
126 /**
127 * @param $position
128 *
129 * @return mixed
130 */
131 public function rtwpvg_image_classes( $classes ) {
132 $controllers = $this->get_settings_for_display();
133 $show_thumbnails = ! empty( $controllers['show_thumbnails'] ) ? $controllers['show_thumbnails'] : false;
134
135 if ( ! $show_thumbnails ) {
136 $key = array_search( 'rtwpvg-has-product-thumbnail', $classes );
137 if ( $key ) {
138 unset( $classes[ $key ] );
139 add_filter( 'rtwpvg_show_product_thumbnail_slider', '__return_false', 20 );
140 }
141 }
142
143 return $classes;
144 }
145
146 public function thumbnails_columns( $column ) {
147 $controllers = $this->get_settings_for_display();
148 $column = ! empty( $controllers['gallery_thumbs_column']['size'] ) ? $controllers['gallery_thumbs_column']['size'] : $column;
149
150 return $column;
151 }
152
153 public function thumbnails_columns_sm( $column ) {
154 $controllers = $this->get_settings_for_display();
155 $column = ! empty( $controllers['gallery_thumbs_column_tablet']['size'] ) ? $controllers['gallery_thumbs_column_tablet']['size'] : $column;
156
157 return $column;
158 }
159
160 public function thumbnails_columns_xs( $column ) {
161 $controllers = $this->get_settings_for_display();
162 $column = ! empty( $controllers['gallery_thumbs_column_mobile']['size'] ) ? $controllers['gallery_thumbs_column_mobile']['size'] : $column;
163
164 return $column;
165 }
166
167 /**
168 * @param $position
169 *
170 * @return mixed
171 */
172 public function thumbnail_position( $position ) {
173 if ( ! function_exists( 'rtwpvg' ) || ! rtwpvg()->active_pro() || ! BuilderFns::is_product() ) {
174 return $position;
175 }
176
177 $controllers = $this->get_settings_for_display();
178 $show_thumbnails = ! empty( $controllers['show_thumbnails'] ) ? $controllers['show_thumbnails'] : false;
179
180 if ( ! $show_thumbnails ) {
181 add_filter( 'rtwpvg_show_product_thumbnail_slider', '__return_false', 20 );
182 return 'bottom';
183 }
184
185 return ! empty( $controllers['image_layout'] ) ? $controllers['image_layout'] : 'bottom';
186 }
187
188 /**
189 * Render Function
190 *
191 * @return void
192 */
193 protected function render() {
194 global $product, $post;
195 $_product = $product;
196 $product = Fns::get_product();
197 $controllers = $this->get_settings_for_display();
198
199 $this->theme_support();
200
201 $controllers['lightbox_icon'] = Fns::icons_manager( $controllers['lightbox_icon'] );
202 $data = [
203 'template' => 'elementor/single-product/product-images',
204 'controllers' => $controllers,
205 ];
206 $this->the_hooks( $controllers );
207
208 Fns::load_template( $data['template'], $data );
209
210 if ( $this->is_edit_mode() ) {
211 $this->editor_scripts();
212 }
213 $this->theme_support( 'render_reset' );
214 $product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
215 }
216
217 }
218