PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.4.2
ShopBuilder – WooCommerce Builder For Elementor v3.4.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
← All changes | app/Modules/QuickView/QuickViewFrontEnd.php +91 -98 2.0.33.4.2 View file →
@@ -1,5 +1,10 @@
1 1 <?php
2 +/**
3 + * Quick View Module Class.
4 + *
5 + * @package RadiusTheme\SB
6 + */
2 7
3 8 namespace RadiusTheme\SB\Modules\QuickView;
4 9
5 10 use RadiusTheme\SB\Helpers\Fns;
@@ -10,24 +15,35 @@
10 15 if ( ! defined( 'ABSPATH' ) ) {
11 16 exit( 'This script cannot be accessed directly.' );
12 17 }
13 18
19 +/**
20 + * Quick View Module Class.
21 + */
14 22 class QuickViewFrontEnd {
15 23 use SingletonTrait;
16 24
25 + /**
26 + * Asset Handle
27 + *
28 + * @var string
29 + */
30 + private $handle = 'rtsb-quick-view';
31 +
32 + /**
33 + * Class constructor.
34 + */
17 35 public function __construct() {
18 - add_action( 'wp_enqueue_scripts', [ $this, 'enqueue' ] );
36 + add_action( 'wp_enqueue_scripts', [ $this, 'enqueue' ], 99 );
19 37
20 - // Gallery Plugin Support rtwpvg_disable_enqueue_scripts
38 + // Gallery Plugin Support rtwpvg_disable_enqueue_scripts.
21 39 add_filter( 'rtwpvg_disable_enqueue_scripts', '__return_false', 11 );
22 40
23 41 // Template.
42 + add_action( 'rtsb/modules/quick_view/frontend/display', [ $this, 'button_hook' ] );
24 43
25 - add_action( 'rtsb/modules/quick_view/frontend/display', [ $this, 'button_hook' ] );
26 - // Add do_action( 'rtsb/modules/quick_view/frontend/display' ); for display anywhere.
44 + add_action( 'rtsb/modules/quick_view/print_button', [ $this, 'print_button' ] );
27 45
28 - add_action( 'rtsb/modules/quick_view/print_button', [ $this, 'print_button' ] );
29 -
30 46 // Load action for product template.
31 47 $this->quick_view_action_template();
32 48
33 49 // ShortCode.
@@ -38,9 +54,8 @@
38 54
39 55 add_action( 'wp_ajax_nopriv_rtsb_load_product_quick_view', [ $this, 'product_quick_view_ajax' ] );
40 56
41 57 $this->attach_button();
42 -
43 58 }
44 59
45 60
46 61 /**
@@ -50,9 +65,9 @@
50 65 * @return void
51 66 * @since 1.0.0
52 67 */
53 68 public function quick_view_action_template() {
54 -
69 + wp_enqueue_style( 'elementor-frontend' );
55 70 // Image.
56 71 add_action( 'rtsb/wcqv/product/image', 'woocommerce_show_product_sale_flash', 10 );
57 72 add_action( 'rtsb/wcqv/product/image', 'woocommerce_show_product_images', 20 );
58 73
@@ -62,21 +77,25 @@
62 77 add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_price', 15 );
63 78 add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_excerpt', 20 );
64 79 add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_add_to_cart', 25 );
65 80 add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_meta', 30 );
66 -
67 81 }
68 82
83 + /**
84 + * Quick View AJAX.
85 + *
86 + * @return void
87 + */
69 88 public function product_quick_view_ajax() {
70 - $product_id = absint( $_REQUEST['product_id'] );
89 + $product_id = isset( $_REQUEST['product_id'] ) ? absint( $_REQUEST['product_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
71 90
72 - if ( empty( $product_id ) ) {
91 + if ( empty( $product_id ) || 'publish' !== get_post_status( $product_id ) ) {
73 92 wp_send_json_error( esc_html__( 'Product Id not found', 'shopbuilder' ) );
74 93 }
75 94
76 95 global $sitepress;
77 96
78 - $lang = isset( $_REQUEST['lang'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['lang'] ) ) : '';
97 + $lang = isset( $_REQUEST['lang'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['lang'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
79 98 if ( defined( 'ICL_LANGUAGE_CODE' ) && $lang && isset( $sitepress ) ) {
80 99 $sitepress->switch_lang( $lang, true );
81 100 }
82 101
@@ -83,22 +102,12 @@
83 102 // Set the main wp query for the product.
84 103 wp( 'p=' . $product_id . '&post_type=product' );
85 104
86 105 // Remove product thumbnails gallery.
87 - if ( defined('RTWPVG_VERSION') ) {
106 + if ( defined( 'RTWPVG_VERSION' ) ) {
88 107 remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
89 108 }
90 - if ( ! defined('RTWPVG_VERSION') ) {
91 - add_action( 'woocommerce_product_thumbnails', [ $this, 'woocommerce_product_thumbnails_before' ], 1 );
92 - add_action( 'woocommerce_product_thumbnails', [ $this, 'woocommerce_product_thumbnails_after'], 25 );
93 - }
94 - // Change template for variable products.
95 - // if ( isset( $GLOBALS['yith_wccl'] ) ) {
96 - // $GLOBALS['yith_wccl']->obj = new YITH_WCCL_Frontend();
97 - // $GLOBALS['yith_wccl']->obj->override();
98 - // } elseif ( defined( 'YITH_WCCL_PREMIUM' ) && YITH_WCCL_PREMIUM && class_exists( 'YITH_WCCL_Frontend' ) ) {
99 - // $attributes = YITH_WCCL_Frontend()->create_attributes_json( $product_id, true );
100 - // }
109 +
101 110 ob_start();
102 111 Fns::load_template( 'quick-view/content' );
103 112 $html = ob_get_contents(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
104 113 ob_end_clean();
@@ -112,9 +121,8 @@
112 121 * @return void
113 122 * @since 1.0.0
114 123 */
115 124 public function attach_button() {
116 -
117 125 $positions = apply_filters(
118 126 'rtsb/module/quick_view/loop_btn_position',
119 127 [
120 128
@@ -126,9 +134,9 @@
126 134 'hook' => 'woocommerce_after_shop_loop_item',
127 135 'priority' => 15,
128 136 ],
129 137 'custom' => [
130 - 'hook' => Fns::get_option( 'modules', 'quick_view', 'loop_custom_hook_name', '' ),
138 + 'hook' => Fns::get_option( 'modules', 'quick_view', 'loop_custom_hook_name', '' ),
131 139 'priority' => Fns::get_option( 'modules', 'quick_view', 'loop_custom_hook_priority', '' ),
132 140 ],
133 141 ]
134 142 );
@@ -133,9 +141,8 @@
133 141 ]
134 142 );
135 143
136 144 // Add the link "Add to wishlist" in the loop.
137 -
138 145 $loop_btn_position = Fns::get_option( 'modules', 'quick_view', 'loop_btn_position', 'after_add_to_cart' );
139 146
140 147 if ( 'shortcode' !== $loop_btn_position && isset( $positions[ $loop_btn_position ]['hook'] ) ) {
141 148 add_action(
@@ -146,9 +153,9 @@
146 153 ],
147 154 isset( $positions[ $loop_btn_position ]['priority'] ) ? $positions[ $loop_btn_position ]['priority'] : ''
148 155 );
149 156 }
150 - // TODO:: Maybe this hooks is not working. Need to Check gutenberg compatibility.
157 +
151 158 // Add the link "Quick view" for Gutenberg blocks.
152 159 add_filter( 'woocommerce_blocks_product_grid_item_html', [ $this, 'add_button_for_block' ], 10, 3 );
153 160 }
154 161
@@ -156,65 +163,52 @@
156 163 * Print "Add to compare" button
157 164 *
158 165 * @return void
159 166 */
160 - public function woocommerce_product_thumbnails_before() { ?>
161 - <div class="rtsb-gallery-images-wrapper">
162 - <?php
163 - }
164 - /**
165 - * Print "Add to compare" button
166 - *
167 - * @return void
168 - */
169 - public function woocommerce_product_thumbnails_after() { ?>
170 - </div>
171 - <?php
172 - }
173 -
174 - /**
175 - * Print "Add to compare" button
176 - *
177 - * @return void
178 - */
179 167 public function button_hook() {
180 168 if ( ! apply_filters( 'rtsb/module/quick_view/show_button', true ) ) {
181 169 return;
182 170 }
183 - global $product;
184 - if( $product instanceof WC_Product ) {
185 - do_action('rtsb/modules/quick_view/print_button', $product->get_id());
186 - }
171 + global $product;
172 + if ( $product instanceof WC_Product ) {
173 + do_action( 'rtsb/modules/quick_view/print_button', $product->get_id() );
174 + }
187 175 }
188 176
189 177
190 178 /**
191 - * @return string|void
179 + * Print "Add to compare" button.
180 + *
181 + * @param int $product_id Product ID.
182 + *
183 + * @return void
192 184 */
193 185 public function print_button( $product_id = 0 ) {
194 186 global $product;
195 187
196 - // product object.
197 - $current_product = $product_id ? wc_get_product( $product_id ) : false;
198 - $current_product = $current_product ?: $product;
188 + if ( ! $product instanceof WC_Product && $product_id ) {
189 + $product = wc_get_product( $product_id );
190 + }
199 191
200 - if ( ! $current_product instanceof WC_Product ) {
201 - return '';
192 + $classes = [];
193 + $button_text = Fns::get_option( 'modules', 'quick_view', 'button_text', esc_html__( 'Quick View', 'shopbuilder' ) );
194 + $has_button_text = ! empty( Fns::get_option( 'modules', 'quick_view', 'button_text', '' ) );
195 +
196 + if ( $has_button_text ) {
197 + $classes[] = 'has-text';
202 198 }
203 199
204 - $classes = []; // button class.
205 - $button_text = Fns::get_option( 'modules', 'quick_view', 'button_text', esc_html__( 'Quick View', 'shopbuilder' ) );
206 -
207 - $icon_html = '<i class="rtsb-icon rtsb-icon-eye"></i>';
200 + $icon_html = '<i class="rtsb-icon rtsb-icon-eye"></i>';
208 201 // get product type.
209 - $product_type = $current_product->get_type();
202 + $product_type = $product->get_type();
210 203 $params = [
211 - 'classes' => $classes,
212 - 'product_id' => $current_product->get_id(),
213 - 'product_type' => $product_type,
214 - 'button_text' => $button_text,
215 - 'left_text' => apply_filters( 'rtsb/module/quick_view/button_left_text', '' ),
216 - 'right_text' => apply_filters( 'rtsb/module/quick_view/button_right_text', '' ),
204 + 'classes' => $classes,
205 + 'product_id' => $product->get_id(),
206 + 'product_type' => $product_type,
207 + 'button_text' => $button_text,
208 + 'has_button_text' => $has_button_text,
209 + 'left_text' => apply_filters( 'rtsb/module/quick_view/button_left_text', '' ),
210 + 'right_text' => apply_filters( 'rtsb/module/quick_view/button_right_text', '' ),
217 211 ];
218 212 // let third party developer filter options.
219 213 $atts = apply_filters( 'rtsb/module/quick_view/button_params', $params );
220 214 // set fragment options.
@@ -222,39 +216,51 @@
222 216
223 217 Fns::load_template( 'quick-view/button', $atts );
224 218 }
225 219
226 -
227 220 /**
228 221 * Wishlist button Shortcode callable function
229 222 *
230 - * @param array $atts
231 - * @param string $content
232 - *
233 - * @return string [HTML]
223 + * @return string
234 224 */
235 - public function button_shortcode( $atts, $content = '' ) {
236 - $this->enqueue();
237 - global $product;
225 + public function button_shortcode() {
226 + global $product;
227 +
238 228 if ( ! $product instanceof WC_Product ) {
239 229 return '';
240 230 }
231 +
241 232 ob_start();
233 + do_action( 'rtsb/modules/quick_view/print_button', $product->get_id() );
242 234
243 - do_action( 'rtsb/modules/quick_view/print_button', $product->get_id() );
244 -
245 - return ob_get_clean();
235 + return ob_get_clean();
246 236 }
247 237
238 + /**
239 + * Enqueue assets.
240 + *
241 + * @return void
242 + */
248 243 public function enqueue() {
244 + wp_enqueue_style( 'elementor-icons-fa-regular' );
245 + wp_enqueue_style( 'elementor-icons-fa-solid' );
246 + wp_enqueue_style( 'elementor-icons-shared-0' );
247 +
248 + if ( ! class_exists( 'WooProductVariationGallery' ) && current_theme_supports( 'wc-product-gallery-slider' ) ) {
249 + wp_enqueue_script( 'wc-flexslider' );
250 + }
251 +
249 252 wp_enqueue_script( 'wc-add-to-cart-variation' );
253 +
250 254 if ( version_compare( WC()->version, '3.0.0', '>=' ) ) {
251 255 if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) {
252 - wp_enqueue_script( 'zoom' );
256 + wp_enqueue_script( 'wc-zoom' );
253 257 }
258 +
254 259 if ( current_theme_supports( 'wc-product-gallery-lightbox' ) ) {
255 - wp_enqueue_script( 'photoswipe-ui-default' );
260 + wp_enqueue_script( 'wc-photoswipe-ui-default' );
256 261 wp_enqueue_style( 'photoswipe-default-skin' );
262 +
257 263 if ( has_action( 'wp_footer', 'woocommerce_photoswipe' ) === false ) {
258 264 add_action( 'wp_footer', 'woocommerce_photoswipe', 15 );
259 265 }
260 266 }
@@ -259,23 +265,10 @@
259 265 }
260 266 }
261 267 wp_enqueue_script( 'wc-single-product' );
262 268 }
263 -
264 - wp_register_style( 'rtsb-modules', rtsb()->get_assets_uri( 'modules/modules.css' ), [], RTSB_VERSION );
265 - wp_register_script(
266 - 'rtsb-quick-view',
267 - rtsb()->get_assets_uri( 'modules/quick-view.js' ),
268 - [
269 - 'jquery',
270 - 'rtsb-public',
271 - ],
272 - RTSB_VERSION,
273 - true
274 - );
275 - wp_enqueue_style( 'rtsb-modules' );
276 - wp_enqueue_script( 'rtsb-quick-view' );
277 -
269 + // Enqueue assets.
270 + $this->handle = Fns::enqueue_module_assets( $this->handle, 'quick-view' );
278 271 // Allow user to load custom style and scripts!
279 272 do_action( 'rtsb/modules/quick_view/custom_scripts' );
280 273
281 274 $params = apply_filters(
@@ -286,9 +279,9 @@
286 279 'isLoggedIn' => is_user_logged_in(),
287 280 ]
288 281 );
289 282
290 - wp_localize_script( 'rtsb-quick-view', 'rtsbQvParams', $params );
283 + wp_localize_script( $this->handle, 'rtsbQvParams', $params );
291 284 }
292 285
293 286
294 287 /**
@@ -301,9 +294,9 @@
301 294 * @return string Filtered HTML.
302 295 */
303 296 public function add_button_for_block( $item_html, $data, $product ) {
304 297 // Add the link "Add to wishlist" in the loop.
305 - $shop_btn_position = Fns::get_option( 'modules', 'quick_view', 'loop_btn_position', 'after_add_to_cart' );
298 + $shop_btn_position = Fns::get_option( 'modules', 'quick_view', 'loop_btn_position', 'after_add_to_cart' );
306 299 ob_start();
307 300 $this->print_button( $product->get_id() );
308 301 $button = ob_get_clean();
309 302 $parts = [];