PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.2.3
ShopBuilder – WooCommerce Builder For Elementor v3.2.3
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/Compare/CompareFrontEnd.php +50 -44 2.2.13.2.3 View file →
@@ -1,5 +1,10 @@
1 1 <?php
2 +/**
3 + * Compare Module Class
4 + *
5 + * @package RadiusTheme\SB
6 + */
2 7
3 8 namespace RadiusTheme\SB\Modules\Compare;
4 9
5 10 use RadiusTheme\SB\Helpers\Fns;
@@ -10,25 +15,31 @@
10 15 if ( ! defined( 'ABSPATH' ) ) {
11 16 exit( 'This script cannot be accessed directly.' );
12 17 }
13 18
14 -
19 +/**
20 + * Compare Module Class
21 + */
15 22 class CompareFrontEnd {
16 23 use SingletonTrait;
17 24
25 + /**
26 + * Asset Handle
27 + *
28 + * @var string
29 + */
30 + private $handle = 'rtsb-compare';
31 +
32 + /**
33 + * Class constructor.
34 + */
18 35 public function __construct() {
19 - // Template
20 -
21 36 add_filter( 'body_class', [ $this, 'add_body_class' ] );
22 -
23 - add_action( 'wp_enqueue_scripts', [ $this, 'enqueue' ] );
24 -
37 + add_action( 'wp_enqueue_scripts', [ $this, 'enqueue' ], 99 );
25 38 add_action( 'rtsb/modules/compare/frontend/display', [ $this, 'button_hook' ] );
26 - // Add do_action('rtsb/modules/compare/frontend/display' ); for display anywhere.
27 -
28 39 add_action( 'rtsb/modules/compare/print_button', [ $this, 'print_button' ] );
29 40
30 - // ShortCode
41 + // ShortCode.
31 42 add_shortcode( 'rtsb_compare_list', [ $this, 'list_shortcode' ] );
32 43 add_shortcode( 'rtsb_compare_button', [ $this, 'button_shortcode' ] );
33 44 add_shortcode( 'rtsb_compare_counter', [ $this, 'counter_shortcode' ] );
34 45
@@ -34,23 +45,16 @@
34 45
35 46 $this->attach_button();
36 47 }
37 48
38 -
49 + /**
50 + * Enqueue assets.
51 + *
52 + * @return void
53 + */
39 54 public function enqueue() {
40 - wp_register_style( 'rtsb-modules', rtsb()->get_assets_uri( 'modules/modules.css' ), [], RTSB_VERSION );
41 - wp_register_script(
42 - 'rtsb-compare',
43 - rtsb()->get_assets_uri( 'modules/compare.js' ),
44 - [
45 - 'jquery',
46 - 'rtsb-public',
47 - ],
48 - RTSB_VERSION,
49 - true
50 - );
51 - wp_enqueue_style( 'rtsb-modules' );
52 - wp_enqueue_script( 'rtsb-compare' );
55 + // Enqueue assets.
56 + $this->handle = Fns::enqueue_module_assets( $this->handle, 'compare' );
53 57 $ajax_button_text = Fns::get_option( 'modules', 'compare', 'button_text', esc_html__( 'Compare', 'shopbuilder' ) );
54 58 $params = apply_filters(
55 59 'rtsb/module/compare/js_params',
56 60 [
@@ -69,9 +73,9 @@
69 73 ],
70 74 ]
71 75 );
72 76
73 - wp_localize_script( 'rtsb-compare', 'rtsbCompareParams', $params );
77 + wp_localize_script( $this->handle, 'rtsbCompareParams', $params );
74 78 }
75 79
76 80 /**
77 81 * Add the "Add to Wishlist" button. Needed to use in wp_head hook.
@@ -163,9 +167,8 @@
163 167 isset( $positions[ $loop_btn_position ]['priority'] ) ? $positions[ $loop_btn_position ]['priority'] : ''
164 168 );
165 169 }
166 170
167 - // TODO:: Maybe this hooks is not working. Need to Check gutenberg compatibility.
168 171 // Add the link "Add to wishlist" for Gutenberg blocks.
169 172 add_filter( 'woocommerce_blocks_product_grid_item_html', [ $this, 'add_button_for_block' ], 10, 3 );
170 173 }
171 174
@@ -233,9 +236,13 @@
233 236 }
234 237
235 238
236 239 /**
237 - * @return string|void
240 + * Print "Add to compare" button
241 + *
242 + * @param int $product_id Product ID.
243 + *
244 + * @return void
238 245 */
239 246 public function print_button( $product_id = 0 ) {
240 247 global $product;
241 248
@@ -242,12 +249,8 @@
242 249 if ( ! $product instanceof WC_Product && $product_id ) {
243 250 $product = wc_get_product( $product_id );
244 251 }
245 252
246 - // if ( ! $current_product instanceof WC_Product ) {
247 - // return '';
248 - // }
249 -
250 253 // product parent.
251 254 $product_parent = $product->get_parent_id();
252 255
253 256 // button class.
@@ -278,9 +281,9 @@
278 281 'product_id' => $product->get_id(),
279 282 'parent_product_id' => $product_parent ?: $product->get_id(),
280 283 'product_type' => $product_type,
281 284 'button_text' => $button_text,
282 - 'show_button_text' => false,
285 + 'show_button_text' => ! empty( Fns::get_option( 'modules', 'compare', 'button_text', '' ) ),
283 286 'left_text' => apply_filters( 'rtsb/module/compare/button_left_text', '' ),
284 287 'right_text' => apply_filters( 'rtsb/module/compare/button_right_text', '' ),
285 288 ];
286 289 $atts = apply_filters( 'rtsb/module/compare/button_params', $params );
@@ -310,17 +313,19 @@
310 313
311 314 /**
312 315 * List Shortcode callable function
313 316 *
314 - * @param array $atts
315 - * @param string $content
317 + * @param array $atts Shortcode attributes.
318 + * @param string $content Shortcode content.
316 319 *
317 320 * @return string [HTML]
318 321 */
319 322 public function list_shortcode( $atts, $content = '' ) {
320 - wp_enqueue_style( 'rtsb-modules' );
321 - wp_enqueue_script( 'rtsb-compare' );
323 + $this->handle = Fns::optimized_handle( $this->handle );
322 324
325 + wp_enqueue_style( $this->handle );
326 + wp_enqueue_script( $this->handle );
327 +
323 328 /* Fetch From option data */
324 329
325 330 $empty_text = Fns::get_option( 'modules', 'compare', 'empty_table_text', esc_html__( 'No product found at your list.', 'shopbuilder' ) );
326 331
@@ -347,17 +352,18 @@
347 352
348 353 /**
349 354 * Compare button Shortcode callable function
350 355 *
351 - * @param array $atts
352 - * @param string $content
353 - *
354 356 * @return string [HTML]
355 357 */
356 - public function button_shortcode( $atts, $content = '' ) {
357 - wp_enqueue_style( 'rtsb-modules' );
358 - wp_enqueue_script( 'rtsb-compare' );
358 + public function button_shortcode() {
359 + $this->handle = Fns::optimized_handle( $this->handle );
360 +
361 + wp_enqueue_style( $this->handle );
362 + wp_enqueue_script( $this->handle );
363 +
359 364 global $product;
365 +
360 366 if ( ! $product instanceof WC_Product ) {
361 367 return '';
362 368 }
363 369 ob_start();
@@ -369,15 +375,15 @@
369 375
370 376 /**
371 377 * Compare counter Shortcode callable function
372 378 *
373 - * @param array $atts
374 - * @param string $content
379 + * @param array $atts Shortcode attributes.
380 + * @param string $content Shortcode content.
375 381 *
376 382 * @return string [HTML]
377 383 */
378 384 public function counter_shortcode( $atts, $content = '' ) {
379 - wp_enqueue_style( 'rtsb-modules' );
385 + wp_enqueue_style( Fns::optimized_handle( $this->handle ) );
380 386
381 387 $product_ids = CompareFns::instance()->get_compared_product_ids();
382 388
383 389 $button_text = esc_html__( 'Compare', 'shopbuilder' );