PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.1.4
ShopBuilder – WooCommerce Builder For Elementor v1.1.4
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 +330 -355 2.0.21.1.4 View file →
@@ -1,355 +1,330 @@
1 -<?php
2 -
3 -namespace RadiusTheme\SB\Modules\QuickView;
4 -
5 -use RadiusTheme\SB\Helpers\Fns;
6 -use RadiusTheme\SB\Traits\SingletonTrait;
7 -use WC_Product;
8 -
9 -// Do not allow directly accessing this file.
10 -if ( ! defined( 'ABSPATH' ) ) {
11 - exit( 'This script cannot be accessed directly.' );
12 -}
13 -
14 -class QuickViewFrontEnd {
15 - use SingletonTrait;
16 -
17 - public function __construct() {
18 - add_action( 'wp_enqueue_scripts', [ $this, 'enqueue' ] );
19 -
20 - // Gallery Plugin Support rtwpvg_disable_enqueue_scripts
21 - add_filter( 'rtwpvg_disable_enqueue_scripts', '__return_false', 11 );
22 -
23 - // Template.
24 -
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.
27 -
28 - add_action( 'rtsb/modules/quick_view/print_button', [ $this, 'print_button' ] );
29 -
30 - // Load action for product template.
31 - $this->quick_view_action_template();
32 -
33 - // ShortCode.
34 - add_shortcode( 'rtsb_quick_view_button', [ $this, 'button_shortcode' ] );
35 -
36 - // Quick view AJAX.
37 - add_action( 'wp_ajax_rtsb_load_product_quick_view', [ $this, 'product_quick_view_ajax' ] );
38 -
39 - add_action( 'wp_ajax_nopriv_rtsb_load_product_quick_view', [ $this, 'product_quick_view_ajax' ] );
40 -
41 - $this->attach_button();
42 -
43 - }
44 -
45 -
46 - /**
47 - * Load wc action for quick view product template
48 - *
49 - * @access public
50 - * @return void
51 - * @since 1.0.0
52 - */
53 - public function quick_view_action_template() {
54 -
55 - // Image.
56 - add_action( 'rtsb/wcqv/product/image', 'woocommerce_show_product_sale_flash', 10 );
57 - add_action( 'rtsb/wcqv/product/image', 'woocommerce_show_product_images', 20 );
58 -
59 - // Summary.
60 - add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_title', 5 );
61 - add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_rating', 10 );
62 - add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_price', 15 );
63 - add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_excerpt', 20 );
64 - add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_add_to_cart', 25 );
65 - add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_meta', 30 );
66 -
67 - }
68 -
69 - public function product_quick_view_ajax() {
70 - $product_id = absint( $_REQUEST['product_id'] );
71 -
72 - if ( empty( $product_id ) ) {
73 - wp_send_json_error( esc_html__( 'Product Id not found', 'shopbuilder' ) );
74 - }
75 -
76 - global $sitepress;
77 -
78 - $lang = isset( $_REQUEST['lang'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['lang'] ) ) : '';
79 - if ( defined( 'ICL_LANGUAGE_CODE' ) && $lang && isset( $sitepress ) ) {
80 - $sitepress->switch_lang( $lang, true );
81 - }
82 -
83 - // Set the main wp query for the product.
84 - wp( 'p=' . $product_id . '&post_type=product' );
85 -
86 - // Remove product thumbnails gallery.
87 - if ( defined('RTWPVG_VERSION') ) {
88 - remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
89 - }
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 - // }
101 - ob_start();
102 - Fns::load_template( 'quick-view/content' );
103 - $html = ob_get_contents(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
104 - ob_end_clean();
105 -
106 - wp_send_json_success( [ 'html' => $html ] );
107 - }
108 -
109 - /**
110 - * Add the "Add to Wishlist" button. Needed to use in wp_head hook.
111 - *
112 - * @return void
113 - * @since 1.0.0
114 - */
115 - public function attach_button() {
116 -
117 - $positions = apply_filters(
118 - 'rtsb/module/quick_view/loop_btn_position',
119 - [
120 -
121 - 'before_add_to_cart' => [
122 - 'hook' => 'woocommerce_after_shop_loop_item',
123 - 'priority' => 7,
124 - ],
125 - 'after_add_to_cart' => [
126 - 'hook' => 'woocommerce_after_shop_loop_item',
127 - 'priority' => 15,
128 - ],
129 - 'custom' => [
130 - 'hook' => Fns::get_option( 'modules', 'quick_view', 'loop_custom_hook_name', '' ),
131 - 'priority' => Fns::get_option( 'modules', 'quick_view', 'loop_custom_hook_priority', '' ),
132 - ],
133 - ]
134 - );
135 -
136 - // Add the link "Add to wishlist" in the loop.
137 -
138 - $loop_btn_position = Fns::get_option( 'modules', 'quick_view', 'loop_btn_position', 'after_add_to_cart' );
139 -
140 - if ( 'shortcode' !== $loop_btn_position && isset( $positions[ $loop_btn_position ]['hook'] ) ) {
141 - add_action(
142 - $positions[ $loop_btn_position ]['hook'],
143 - [
144 - $this,
145 - 'button_hook',
146 - ],
147 - isset( $positions[ $loop_btn_position ]['priority'] ) ? $positions[ $loop_btn_position ]['priority'] : ''
148 - );
149 - }
150 - // TODO:: Maybe this hooks is not working. Need to Check gutenberg compatibility.
151 - // Add the link "Quick view" for Gutenberg blocks.
152 - add_filter( 'woocommerce_blocks_product_grid_item_html', [ $this, 'add_button_for_block' ], 10, 3 );
153 - }
154 -
155 - /**
156 - * Print "Add to compare" button
157 - *
158 - * @return void
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 - */
179 - public function button_hook() {
180 - if ( ! apply_filters( 'rtsb/module/quick_view/show_button', true ) ) {
181 - return;
182 - }
183 - global $product;
184 - if( $product instanceof WC_Product ) {
185 - do_action('rtsb/modules/quick_view/print_button', $product->get_id());
186 - }
187 - }
188 -
189 -
190 - /**
191 - * @return string|void
192 - */
193 - public function print_button( $product_id = 0 ) {
194 - global $product;
195 -
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 '';
202 - }
203 -
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>';
208 - // get product type.
209 - $product_type = $current_product->get_type();
210 - $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', '' ),
217 - ];
218 - // let third party developer filter options.
219 - $atts = apply_filters( 'rtsb/module/quick_view/button_params', $params );
220 - // set fragment options.
221 - $atts['icon_html'] = apply_filters( 'rtsb/module/quick_view/icon_html', $icon_html, $atts );
222 -
223 - Fns::load_template( 'quick-view/button', $atts );
224 - }
225 -
226 -
227 - /**
228 - * Wishlist button Shortcode callable function
229 - *
230 - * @param array $atts
231 - * @param string $content
232 - *
233 - * @return string [HTML]
234 - */
235 - public function button_shortcode( $atts, $content = '' ) {
236 - $this->enqueue();
237 - global $product;
238 - if ( ! $product instanceof WC_Product ) {
239 - return '';
240 - }
241 - ob_start();
242 -
243 - do_action( 'rtsb/modules/quick_view/print_button', $product->get_id() );
244 -
245 - return ob_get_clean();
246 - }
247 -
248 - public function enqueue() {
249 - wp_enqueue_script( 'wc-add-to-cart-variation' );
250 - if ( version_compare( WC()->version, '3.0.0', '>=' ) ) {
251 - if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) {
252 - wp_enqueue_script( 'zoom' );
253 - }
254 - if ( current_theme_supports( 'wc-product-gallery-lightbox' ) ) {
255 - wp_enqueue_script( 'photoswipe-ui-default' );
256 - wp_enqueue_style( 'photoswipe-default-skin' );
257 - if ( has_action( 'wp_footer', 'woocommerce_photoswipe' ) === false ) {
258 - add_action( 'wp_footer', 'woocommerce_photoswipe', 15 );
259 - }
260 - }
261 - wp_enqueue_script( 'wc-single-product' );
262 - }
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 -
278 - // Allow user to load custom style and scripts!
279 - do_action( 'rtsb/modules/quick_view/custom_scripts' );
280 -
281 - $params = apply_filters(
282 - 'rtsb/module/quick_view/js_params',
283 - [
284 - 'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ),
285 - 'lang' => defined( 'ICL_LANGUAGE_CODE' ) ? ICL_LANGUAGE_CODE : '',
286 - 'isLoggedIn' => is_user_logged_in(),
287 - ]
288 - );
289 -
290 - wp_localize_script( 'rtsb-quick-view', 'rtsbQvParams', $params );
291 - }
292 -
293 -
294 - /**
295 - * Add ATW button to Products block item
296 - *
297 - * @param string $item_html HTML of the single block item.
298 - * @param array $data Data used to render the item.
299 - * @param WC_Product $product Current product.
300 - *
301 - * @return string Filtered HTML.
302 - */
303 - public function add_button_for_block( $item_html, $data, $product ) {
304 - // 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' );
306 - ob_start();
307 - $this->print_button( $product->get_id() );
308 - $button = ob_get_clean();
309 - $parts = [];
310 -
311 - preg_match( '/(<li class=".*?">)[\S|\s]*?(<a .*?>[\S|\s]*?<\/a>)([\S|\s]*?)(<\/li>)/', $item_html, $parts );
312 -
313 - if ( ! $parts || count( $parts ) < 5 ) {
314 - return $item_html;
315 - }
316 -
317 - // removes first match (entire match).
318 - array_shift( $parts );
319 -
320 - // removes empty parts.
321 - $parts = array_filter( $parts );
322 -
323 - // searches for index to cut parts array.
324 - switch ( $shop_btn_position ) {
325 -
326 - case 'before_add_to_cart':
327 - $index = 2;
328 - break;
329 - case 'after_add_to_cart':
330 - $index = 3;
331 - break;
332 - default:
333 - $index = 0;
334 - break;
335 - }
336 -
337 - // if index is found, stitch button in correct position.
338 - if ( $index ) {
339 - $first_set = array_slice( $parts, 0, $index );
340 - $second_set = array_slice( $parts, $index );
341 -
342 - $parts = array_merge(
343 - $first_set,
344 - (array) $button,
345 - $second_set
346 - );
347 -
348 - // replace li classes.
349 - $parts[0] = preg_replace( '/class="(.*)"/', 'class="$1 rtsb-quick-view-btn-' . $shop_btn_position . '"', $parts[0] );
350 - }
351 -
352 - // join all parts together and return item.
353 - return implode( '', $parts );
354 - }
355 -}
1 +<?php
2 +
3 +namespace RadiusTheme\SB\Modules\QuickView;
4 +
5 +use RadiusTheme\SB\Helpers\Fns;
6 +use RadiusTheme\SB\Traits\SingletonTrait;
7 +use WC_Product;
8 +
9 +// Do not allow directly accessing this file.
10 +if ( ! defined( 'ABSPATH' ) ) {
11 + exit( 'This script cannot be accessed directly.' );
12 +}
13 +
14 +class QuickViewFrontEnd {
15 + use SingletonTrait;
16 +
17 + public function __construct() {
18 + add_action( 'wp_enqueue_scripts', [ $this, 'enqueue' ] );
19 +
20 + // Template.
21 + add_action( 'init', [ $this, 'attach_button' ] );
22 +
23 + add_action( 'rtsb/modules/quick_view/frontend/display', [ $this, 'button_hook' ] );
24 + // Add do_action( 'rtsb/modules/quick_view/frontend/display' ); for display anywhere.
25 +
26 + add_action( 'rtsb/modules/quick_view/print_button', [ $this, 'print_button' ] );
27 +
28 + // Load action for product template.
29 + $this->quick_view_action_template();
30 +
31 + // ShortCode.
32 + add_shortcode( 'rtsb_quick_view_button', [ $this, 'button_shortcode' ] );
33 +
34 + // Quick view AJAX.
35 + add_action( 'wp_ajax_rtsb_load_product_quick_view', [ $this, 'product_quick_view_ajax' ] );
36 + add_action( 'wp_ajax_nopriv_rtsb_load_product_quick_view', [ $this, 'product_quick_view_ajax' ] );
37 +
38 + }
39 +
40 +
41 + /**
42 + * Load wc action for quick view product template
43 + *
44 + * @access public
45 + * @return void
46 + * @since 1.0.0
47 + */
48 + public function quick_view_action_template() {
49 +
50 + // Image.
51 + add_action( 'rtsb/wcqv/product/image', 'woocommerce_show_product_sale_flash', 10 );
52 + add_action( 'rtsb/wcqv/product/image', 'woocommerce_show_product_images', 20 );
53 +
54 + // Summary.
55 + add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_title', 5 );
56 + add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_rating', 10 );
57 + add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_price', 15 );
58 + add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_excerpt', 20 );
59 + add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_add_to_cart', 25 );
60 + add_action( 'rtsb/wcqv/product/summary', 'woocommerce_template_single_meta', 30 );
61 +
62 + }
63 +
64 + public function product_quick_view_ajax() {
65 + $product_id = absint( $_REQUEST['product_id'] );
66 +
67 + if ( empty( $product_id ) ) {
68 + wp_send_json_error( esc_html__( 'Product Id not found', 'shopbuilder' ) );
69 + }
70 +
71 + global $sitepress;
72 +
73 + $lang = isset( $_REQUEST['lang'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['lang'] ) ) : '';
74 + if ( defined( 'ICL_LANGUAGE_CODE' ) && $lang && isset( $sitepress ) ) {
75 + $sitepress->switch_lang( $lang, true );
76 + }
77 +
78 + // Set the main wp query for the product.
79 + wp( 'p=' . $product_id . '&post_type=product' );
80 +
81 + // Remove product thumbnails gallery.
82 + remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
83 + // Change template for variable products.
84 + // if ( isset( $GLOBALS['yith_wccl'] ) ) {
85 + // $GLOBALS['yith_wccl']->obj = new YITH_WCCL_Frontend();
86 + // $GLOBALS['yith_wccl']->obj->override();
87 + // } elseif ( defined( 'YITH_WCCL_PREMIUM' ) && YITH_WCCL_PREMIUM && class_exists( 'YITH_WCCL_Frontend' ) ) {
88 + // $attributes = YITH_WCCL_Frontend()->create_attributes_json( $product_id, true );
89 + // }
90 + ob_start();
91 + Fns::load_template( 'quick-view/content' );
92 + $html = ob_get_contents(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
93 + ob_end_clean();
94 +
95 + wp_send_json_success( [ 'html' => $html ] );
96 + }
97 +
98 + /**
99 + * Add the "Add to Wishlist" button. Needed to use in wp_head hook.
100 + *
101 + * @return void
102 + * @since 1.0.0
103 + */
104 + public function attach_button() {
105 +
106 + $positions = apply_filters(
107 + 'rtsb/module/quick_view/loop_btn_position',
108 + [
109 + 'top_thumbnail' => [
110 + 'hook' => 'woocommerce_before_shop_loop_item',
111 + 'priority' => 5,
112 + ],
113 + 'before_add_to_cart' => [
114 + 'hook' => 'woocommerce_after_shop_loop_item',
115 + 'priority' => 7,
116 + ],
117 + 'after_add_to_cart' => [
118 + 'hook' => 'woocommerce_after_shop_loop_item',
119 + 'priority' => 15,
120 + ],
121 + 'custom' => [
122 + 'hook' => Fns::get_option( 'modules', 'quick_view', 'loop_custom_hook_name', '' ),
123 + 'priority' => Fns::get_option( 'modules', 'quick_view', 'loop_custom_hook_priority', '' ),
124 + ],
125 + ]
126 + );
127 +
128 + // Add the link "Add to wishlist" in the loop.
129 +
130 + $loop_btn_position = Fns::get_option( 'modules', 'quick_view', 'loop_btn_position', 'after_add_to_cart' );
131 +
132 + if ( 'shortcode' !== $loop_btn_position && isset( $positions[ $loop_btn_position ]['hook'] ) ) {
133 + add_action(
134 + $positions[ $loop_btn_position ]['hook'],
135 + [
136 + $this,
137 + 'button_hook',
138 + ],
139 + isset( $positions[ $loop_btn_position ]['priority'] ) ? $positions[ $loop_btn_position ]['priority'] : ''
140 + );
141 + }
142 +
143 + // Add the link "Quick view" for Gutenberg blocks.
144 + add_filter( 'woocommerce_blocks_product_grid_item_html', [ $this, 'add_button_for_block' ], 10, 3 );
145 + }
146 +
147 + /**
148 + * Print "Add to compare" button
149 + *
150 + * @return void
151 + */
152 + public function button_hook() {
153 + if ( ! apply_filters( 'rtsb/module/quick_view/show_button', true ) ) {
154 + return;
155 + }
156 + global $product;
157 + if( $product instanceof WC_Product ) {
158 + do_action('rtsb/modules/quick_view/print_button', $product->get_id());
159 + }
160 + }
161 +
162 +
163 + /**
164 + * @return string|void
165 + */
166 + public function print_button( $product_id = 0 ) {
167 + global $product;
168 +
169 + // product object.
170 + $current_product = $product_id ? wc_get_product( $product_id ) : false;
171 + $current_product = $current_product ?: $product;
172 +
173 + if ( ! $current_product instanceof WC_Product ) {
174 + return '';
175 + }
176 +
177 + $classes = []; // button class.
178 + $button_text = Fns::get_option( 'modules', 'quick_view', 'button_text', esc_html__( 'Quick View', 'shopbuilder' ) );
179 +
180 + $icon_html = '<i class="rtsb-icon rtsb-icon-eye"></i>';
181 + // get product type.
182 + $product_type = $current_product->get_type();
183 + $params = [
184 + 'classes' => $classes,
185 + 'product_id' => $current_product->get_id(),
186 + 'product_type' => $product_type,
187 + 'button_text' => $button_text,
188 + 'left_text' => apply_filters( 'rtsb/module/quick_view/button_left_text', '' ),
189 + 'right_text' => apply_filters( 'rtsb/module/quick_view/button_right_text', '' ),
190 + ];
191 + // let third party developer filter options.
192 + $atts = apply_filters( 'rtsb/module/quick_view/button_params', $params );
193 + // set fragment options.
194 + $atts['icon_html'] = apply_filters( 'rtsb/module/quick_view/icon_html', $icon_html, $atts );
195 +
196 + Fns::load_template( 'quick-view/button', $atts );
197 + }
198 +
199 +
200 + /**
201 + * Wishlist button Shortcode callable function
202 + *
203 + * @param array $atts
204 + * @param string $content
205 + *
206 + * @return string [HTML]
207 + */
208 + public function button_shortcode( $atts, $content = '' ) {
209 + $this->enqueue();
210 + global $product;
211 + if ( ! $product instanceof WC_Product ) {
212 + return '';
213 + }
214 + ob_start();
215 +
216 + do_action( 'rtsb/modules/quick_view/print_button', $product->get_id() );
217 +
218 + return ob_get_clean();
219 + }
220 +
221 + public function enqueue() {
222 + wp_enqueue_script( 'wc-add-to-cart-variation' );
223 + if ( version_compare( WC()->version, '3.0.0', '>=' ) ) {
224 + if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) {
225 + wp_enqueue_script( 'zoom' );
226 + }
227 + if ( current_theme_supports( 'wc-product-gallery-lightbox' ) ) {
228 + wp_enqueue_script( 'photoswipe-ui-default' );
229 + wp_enqueue_style( 'photoswipe-default-skin' );
230 + if ( has_action( 'wp_footer', 'woocommerce_photoswipe' ) === false ) {
231 + add_action( 'wp_footer', 'woocommerce_photoswipe', 15 );
232 + }
233 + }
234 + wp_enqueue_script( 'wc-single-product' );
235 + }
236 +
237 + wp_register_style( 'rtsb-modules', rtsb()->get_assets_uri( 'modules/modules.css' ), [], RTSB_VERSION );
238 + wp_register_script(
239 + 'rtsb-quick-view',
240 + rtsb()->get_assets_uri( 'modules/quick-view.js' ),
241 + [
242 + 'jquery',
243 + 'rtsb-public',
244 + ],
245 + RTSB_VERSION,
246 + true
247 + );
248 + wp_enqueue_style( 'rtsb-modules' );
249 + wp_enqueue_script( 'rtsb-quick-view' );
250 +
251 + // Allow user to load custom style and scripts!
252 + do_action( 'rtsb/modules/quick_view/custom_scripts' );
253 +
254 + $params = apply_filters(
255 + 'rtsb/module/quick_view/js_params',
256 + [
257 + 'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ),
258 + 'lang' => defined( 'ICL_LANGUAGE_CODE' ) ? ICL_LANGUAGE_CODE : '',
259 + 'isLoggedIn' => is_user_logged_in(),
260 + ]
261 + );
262 +
263 + wp_localize_script( 'rtsb-quick-view', 'rtsbQvParams', $params );
264 + }
265 +
266 +
267 + /**
268 + * Add ATW button to Products block item
269 + *
270 + * @param string $item_html HTML of the single block item.
271 + * @param array $data Data used to render the item.
272 + * @param WC_Product $product Current product.
273 + *
274 + * @return string Filtered HTML.
275 + */
276 + public function add_button_for_block( $item_html, $data, $product ) {
277 + // Add the link "Add to wishlist" in the loop.
278 + $shop_btn_position = Fns::get_option( 'modules', 'quick_view', 'loop_btn_position', 'after_add_to_cart' );
279 + ob_start();
280 + $this->print_button( $product->get_id() );
281 + $button = ob_get_clean();
282 + $parts = [];
283 +
284 + preg_match( '/(<li class=".*?">)[\S|\s]*?(<a .*?>[\S|\s]*?<\/a>)([\S|\s]*?)(<\/li>)/', $item_html, $parts );
285 +
286 + if ( ! $parts || count( $parts ) < 5 ) {
287 + return $item_html;
288 + }
289 +
290 + // removes first match (entire match).
291 + array_shift( $parts );
292 +
293 + // removes empty parts.
294 + $parts = array_filter( $parts );
295 +
296 + // searches for index to cut parts array.
297 + switch ( $shop_btn_position ) {
298 + case 'top_thumbnail':
299 + $index = 1;
300 + break;
301 + case 'before_add_to_cart':
302 + $index = 2;
303 + break;
304 + case 'after_add_to_cart':
305 + $index = 3;
306 + break;
307 + default:
308 + $index = 0;
309 + break;
310 + }
311 +
312 + // if index is found, stitch button in correct position.
313 + if ( $index ) {
314 + $first_set = array_slice( $parts, 0, $index );
315 + $second_set = array_slice( $parts, $index );
316 +
317 + $parts = array_merge(
318 + $first_set,
319 + (array) $button,
320 + $second_set
321 + );
322 +
323 + // replace li classes.
324 + $parts[0] = preg_replace( '/class="(.*)"/', 'class="$1 rtsb-quick-view-btn-' . $shop_btn_position . '"', $parts[0] );
325 + }
326 +
327 + // join all parts together and return item.
328 + return implode( '', $parts );
329 + }
330 +}