PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.2.5
ShopBuilder – WooCommerce Builder For Elementor v3.2.5
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 +86 -98 2.0.23.2.5 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,47 @@
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;
199 -
200 - if ( ! $current_product instanceof WC_Product ) {
201 - return '';
188 + if ( ! $product instanceof WC_Product && $product_id ) {
189 + $product = wc_get_product( $product_id );
202 190 }
203 191
204 - $classes = []; // button class.
205 - $button_text = Fns::get_option( 'modules', 'quick_view', 'button_text', esc_html__( 'Quick View', 'shopbuilder' ) );
192 + $classes = [];
193 + $button_text = Fns::get_option( 'modules', 'quick_view', 'button_text', esc_html__( 'Quick View', 'shopbuilder' ) );
206 194
207 - $icon_html = '<i class="rtsb-icon rtsb-icon-eye"></i>';
195 + $icon_html = '<i class="rtsb-icon rtsb-icon-eye"></i>';
208 196 // get product type.
209 - $product_type = $current_product->get_type();
197 + $product_type = $product->get_type();
210 198 $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', '' ),
199 + 'classes' => $classes,
200 + 'product_id' => $product->get_id(),
201 + 'product_type' => $product_type,
202 + 'button_text' => $button_text,
203 + 'has_button_text' => ! empty( Fns::get_option( 'modules', 'quick_view', 'button_text', '' ) ),
204 + 'left_text' => apply_filters( 'rtsb/module/quick_view/button_left_text', '' ),
205 + 'right_text' => apply_filters( 'rtsb/module/quick_view/button_right_text', '' ),
217 206 ];
218 207 // let third party developer filter options.
219 208 $atts = apply_filters( 'rtsb/module/quick_view/button_params', $params );
220 209 // set fragment options.
@@ -222,39 +211,51 @@
222 211
223 212 Fns::load_template( 'quick-view/button', $atts );
224 213 }
225 214
226 -
227 215 /**
228 216 * Wishlist button Shortcode callable function
229 217 *
230 - * @param array $atts
231 - * @param string $content
232 - *
233 - * @return string [HTML]
218 + * @return string
234 219 */
235 - public function button_shortcode( $atts, $content = '' ) {
236 - $this->enqueue();
237 - global $product;
220 + public function button_shortcode() {
221 + global $product;
222 +
238 223 if ( ! $product instanceof WC_Product ) {
239 224 return '';
240 225 }
226 +
241 227 ob_start();
228 + do_action( 'rtsb/modules/quick_view/print_button', $product->get_id() );
242 229
243 - do_action( 'rtsb/modules/quick_view/print_button', $product->get_id() );
244 -
245 - return ob_get_clean();
230 + return ob_get_clean();
246 231 }
247 232
233 + /**
234 + * Enqueue assets.
235 + *
236 + * @return void
237 + */
248 238 public function enqueue() {
239 + wp_enqueue_style( 'elementor-icons-fa-regular' );
240 + wp_enqueue_style( 'elementor-icons-fa-solid' );
241 + wp_enqueue_style( 'elementor-icons-shared-0' );
242 +
243 + if ( ! class_exists( 'WooProductVariationGallery' ) && current_theme_supports( 'wc-product-gallery-slider' ) ) {
244 + wp_enqueue_script( 'wc-flexslider' );
245 + }
246 +
249 247 wp_enqueue_script( 'wc-add-to-cart-variation' );
248 +
250 249 if ( version_compare( WC()->version, '3.0.0', '>=' ) ) {
251 250 if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) {
252 - wp_enqueue_script( 'zoom' );
251 + wp_enqueue_script( 'wc-zoom' );
253 252 }
253 +
254 254 if ( current_theme_supports( 'wc-product-gallery-lightbox' ) ) {
255 - wp_enqueue_script( 'photoswipe-ui-default' );
255 + wp_enqueue_script( 'wc-photoswipe-ui-default' );
256 256 wp_enqueue_style( 'photoswipe-default-skin' );
257 +
257 258 if ( has_action( 'wp_footer', 'woocommerce_photoswipe' ) === false ) {
258 259 add_action( 'wp_footer', 'woocommerce_photoswipe', 15 );
259 260 }
260 261 }
@@ -259,23 +260,10 @@
259 260 }
260 261 }
261 262 wp_enqueue_script( 'wc-single-product' );
262 263 }
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 -
264 + // Enqueue assets.
265 + $this->handle = Fns::enqueue_module_assets( $this->handle, 'quick-view' );
278 266 // Allow user to load custom style and scripts!
279 267 do_action( 'rtsb/modules/quick_view/custom_scripts' );
280 268
281 269 $params = apply_filters(
@@ -286,9 +274,9 @@
286 274 'isLoggedIn' => is_user_logged_in(),
287 275 ]
288 276 );
289 277
290 - wp_localize_script( 'rtsb-quick-view', 'rtsbQvParams', $params );
278 + wp_localize_script( $this->handle, 'rtsbQvParams', $params );
291 279 }
292 280
293 281
294 282 /**
@@ -301,9 +289,9 @@
301 289 * @return string Filtered HTML.
302 290 */
303 291 public function add_button_for_block( $item_html, $data, $product ) {
304 292 // 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' );
293 + $shop_btn_position = Fns::get_option( 'modules', 'quick_view', 'loop_btn_position', 'after_add_to_cart' );
306 294 ob_start();
307 295 $this->print_button( $product->get_id() );
308 296 $button = ob_get_clean();
309 297 $parts = [];