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