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/Controllers/Hooks/ActionHooks.php +210 -26 2.1.63.2.5 View file →
@@ -7,12 +7,14 @@
7 7
8 8 namespace RadiusTheme\SB\Controllers\Hooks;
9 9
10 10 use RadiusTheme\SB\Helpers\Fns;
11 +use RadiusTheme\SB\Helpers\Cache;
11 12 use RadiusTheme\SB\Models\GeneralList;
12 13 use RadiusTheme\SB\Helpers\BuilderFns;
13 14 use RadiusTheme\SB\Models\TemplateSettings;
14 15 use RadiusTheme\SB\Elementor\Render\Render;
16 +use RadiusTheme\SB\Elementor\Helper\RenderHelpers;
15 17
16 18 defined( 'ABSPATH' ) || exit();
17 19
18 20 /**
@@ -24,8 +26,9 @@
24 26 *
25 27 * @return void
26 28 */
27 29 public static function init_hooks() {
30 + add_action( 'rtsb/before/save/options', [ __CLASS__, 'clear_cron_schedule' ], 10, 3 );
28 31 add_action( 'wp_head', [ __CLASS__, 'og_metatags_for_sharing' ], 1 );
29 32 add_action( 'woocommerce_share', [ __CLASS__, 'shopbuilder_share' ], 20 );
30 33 add_action( 'rtsb/wcqv/product/summary', [ __CLASS__, 'shopbuilder_share' ], 40 );
31 34 add_action( 'rtsb/shop/product/image', [ __CLASS__, 'render_image' ], 10, 2 );
@@ -60,9 +63,8 @@
60 63
61 64 /**
62 65 * Notices.
63 66 */
64 - // add_action( 'woocommerce_cart_is_empty', [ Fns::class, 'woocommerce_output_all_notices' ], 5 );
65 67 add_action( 'woocommerce_shortcode_before_product_cat_loop', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
66 68 add_action( 'woocommerce_before_shop_loop', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
67 69 add_action( 'woocommerce_before_single_product', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
68 70 add_action( 'woocommerce_before_cart', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
@@ -81,11 +83,57 @@
81 83 add_action( 'woocommerce_before_checkout_form', [ __CLASS__, 'woocommerce_checkout_coupon_form' ], 10 );
82 84 // My Account Order Page.
83 85 add_action( 'woocommerce_before_account_orders', [ __CLASS__, 'before_account_orders' ], 10 );
84 86 add_action( 'woocommerce_after_account_orders', [ __CLASS__, 'after_account_orders' ], 10 );
87 +
88 + // Product Filter Widget Hooks.
89 + add_action( 'rtsb/before/archive/default/filter/items', [ __CLASS__,'default_filter_header' ], 10 );
90 + add_action( 'rtsb/before/archive/default/filter/items', [ __CLASS__,'default_filter_search' ], 15 );
91 +
92 + // WC Query modifier.
93 + if ( ! rtsb()->has_pro() ) {
94 + add_action( 'woocommerce_product_query', [ __CLASS__, 'query_modifier' ], 15 );
95 + }
96 +
97 + add_action( 'switch_theme', [ __CLASS__, 'clear_cache' ] );
85 98 }
99 + /**
100 + * Clear scheduled cron events when a module is deactivated.
101 + *
102 + * Checks the given block ID against predefined schedules and clears
103 + * related cron hooks if the corresponding module is turned off.
104 + *
105 + * @param string $section_id Section identifier (not used in this function).
106 + * @param string $block_id Module/block identifier to check scheduled hooks.
107 + * @param array $rawOptions Module options array containing 'active' status.
108 + *
109 + * @return void
110 + */
111 + public static function clear_cron_schedule( $section_id, $block_id, $rawOptions ) {
112 + $schedule = [
113 + 'abandoned_cart_recovery' => [
114 + 'rtsb_abandoned_cart_recovery_action',
115 + 'rtsb_send_abandoned_cart_emails',
116 + ],
117 + 'currency_switcher' => [
118 + 'update_exchange_rates_hourly',
119 + ],
120 + ];
121 + if ( ! isset( $schedule[ $block_id ] ) ) {
122 + return;
123 + }
124 + if ( ! isset( $rawOptions['active'] ) ) {
125 + return;
126 + }
127 + if ( 'on' === $rawOptions['active'] ) {
128 + return;
129 + }
130 + // CLear All Custom Schedule If module disabled.
131 + foreach ( $schedule[ $block_id ] as $hook ) {
132 + wp_clear_scheduled_hook( $hook );
133 + }
134 + }
86 135
87 -
88 136 /**
89 137 * @param boolen $has_orders Order exist or not.
90 138 *
91 139 * @return void
@@ -112,9 +160,9 @@
112 160 * @return void
113 161 */
114 162 public static function woocommerce_checkout_coupon_form() {
115 163 echo '<div class="rtsb-notice">';
116 - woocommerce_checkout_coupon_form();
164 + woocommerce_checkout_coupon_form();
117 165 echo '</div>';
118 166 }
119 167
120 168 /**
@@ -134,9 +182,8 @@
134 182 wc_empty_cart_message();
135 183 echo '</div>';
136 184 }
137 185
138 -
139 186 /**
140 187 * @param int $post_id Post Ids.
141 188 * @param object $post Post Object.
142 189 *
@@ -145,42 +192,65 @@
145 192 public static function deleted_post( $post_id, $post ) {
146 193 if ( BuilderFns::$post_type_tb !== $post->post_type ) {
147 194 return;
148 195 }
196 +
149 197 $options = BuilderFns::option_name_for_specific_product_set_default( $post_id );
198 + TemplateSettings::instance()->delete_option( $options );
150 199
151 - if ( TemplateSettings::instance()->get_option( $options ) ) {
152 - TemplateSettings::instance()->delete_option( $options );
153 - }
154 -
155 200 $template_options = BuilderFns::option_name_by_template_id( $post_id );
156 - if ( TemplateSettings::instance()->get_option( $template_options ) ) {
157 - TemplateSettings::instance()->delete_option( $template_options );
158 - }
201 + TemplateSettings::instance()->delete_option( $template_options );
159 202
160 203 $archive_options = BuilderFns::archive_option_name_by_template_id( $post_id );
161 - if ( TemplateSettings::instance()->get_option( $archive_options ) ) {
162 - TemplateSettings::instance()->delete_option( $archive_options );
163 - }
204 + TemplateSettings::instance()->delete_option( $archive_options );
164 205
165 206 $category_options = BuilderFns::option_name_for_specific_category_set_default( $post_id );
166 - if ( TemplateSettings::instance()->get_option( $category_options ) ) {
167 - TemplateSettings::instance()->delete_option( $category_options );
207 + TemplateSettings::instance()->delete_option( $category_options );
208 +
209 + $selected_category_options = BuilderFns::archive_option_name_by_template_id( $post_id );
210 + TemplateSettings::instance()->delete_option( $selected_category_options );
211 +
212 + // Delete Data From Options.
213 + $options_product_selected_cat = BuilderFns::option_name_product_page_selected_cat( $post_id );
214 + $cat_list = TemplateSettings::instance()->get_option( $options_product_selected_cat );
215 + if ( ! empty( $cat_list ) ) {
216 + foreach ( $cat_list as $old_slug ) {
217 + $OldcatList = get_term_by( 'slug', $old_slug, 'product_cat' );
218 + if ( ! empty( $OldcatList ) && ! is_wp_error( $OldcatList ) ) {
219 + delete_term_meta( $OldcatList->term_id, BuilderFns::$categories_product_page_template, $post_id );
220 + }
221 + }
168 222 }
223 + TemplateSettings::instance()->delete_option( $options_product_selected_cat );
169 224
170 - $selected_category_options = BuilderFns::archive_option_name_by_template_id( $post_id );
171 - if ( TemplateSettings::instance()->get_option( $selected_category_options ) ) {
172 - TemplateSettings::instance()->delete_option( $selected_category_options );
225 + $set_default_option = BuilderFns::option_name_product_page_specific_cat_set_default( $post_id );
226 + TemplateSettings::instance()->delete_option( $set_default_option );
227 +
228 + // Tags Remove.
229 + $options_product_selected_tag = BuilderFns::option_name_product_page_selected_tag( $post_id );
230 + $tag_list = TemplateSettings::instance()->get_option( $options_product_selected_tag );
231 + if ( ! empty( $tag_list ) ) {
232 + foreach ( $tag_list as $old_slug ) {
233 + $OldTagList = get_term_by( 'slug', $old_slug, 'product_tag' );
234 + if ( ! empty( $OldTagList ) && ! is_wp_error( $OldTagList ) ) {
235 + delete_term_meta( $OldTagList->term_id, BuilderFns::$tags_product_page_template, $post_id );
236 + }
237 + }
173 238 }
239 + TemplateSettings::instance()->delete_option( $options_product_selected_tag );
174 240
241 + // Tag Set Default Option.
242 + $tag_set_default_option = BuilderFns::option_name_product_page_specific_tag_set_default( $post_id );
243 + TemplateSettings::instance()->delete_option( $tag_set_default_option );
244 +
175 245 global $wpdb;
176 246 // Prepare and execute the SQL query.
177 247 $sql = $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %d", BuilderFns::$view_template_for_products_meta, $post_id );
178 - $wpdb->query( $sql );
248 + $wpdb->query( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching
179 249
180 250 // Prepare and execute the SQL query.
181 251 $sql = $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE meta_key = %s AND meta_value = %d", BuilderFns::$view_template_for_archive_meta, $post_id );
182 - $wpdb->query( $sql );
252 + $wpdb->query( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching
183 253 }
184 254 /**
185 255 * Meta tags for social sharing.
186 256 *
@@ -209,9 +279,11 @@
209 279 $settings['share_platforms'] = $share_platforms;
210 280 $settings['layout'] = ! empty( $generalList['social_share']['share_icon_layout'] ) ? $generalList['social_share']['share_icon_layout'] : 1;
211 281 $settings['show_share_icon'] = 1;
212 282
213 - // TODO:: Implement Later ! empty( $generalList['social_share']['share_icon_show_to_product_page'] ) && 'on' === $generalList['social_share']['share_icon_show_to_product_page'];
283 + /**
284 + * Implement Later ! empty( $generalList['social_share']['share_icon_show_to_product_page'] ) && 'on' === $generalList['social_share']['share_icon_show_to_product_page'];
285 + */
214 286 Fns::print_html( Render::instance()->social_share_view( 'elementor/general/social-share', $settings ), true );
215 287 }
216 288
217 289 /**
@@ -248,13 +320,12 @@
248 320 /**
249 321 * Render image.
250 322 *
251 323 * @param array $args Image args.
252 - * @param array $settings Settings array.
253 324 *
254 325 * @return void
255 326 */
256 - public static function render_image( $args, $settings ) {
327 + public static function render_image( $args ) {
257 328 if ( $args['image_link'] ) {
258 329 $aria_label = esc_attr(
259 330 /* translators: Product Name */
260 331 sprintf( __( 'Image link for Product: %s', 'shopbuilder' ), $args['title'] )
@@ -284,10 +355,18 @@
284 355 */
285 356 public static function modify_wc_query_args( $settings ) {
286 357 if ( ( isset( $settings['tax_relation'] ) && 'OR' === $settings['tax_relation'] ) ||
287 358 ( isset( $settings['relation'] ) && 'OR' === $settings['relation'] ) ) {
288 - add_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args' ], 10, 2 );
359 + add_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args_or' ], 10, 2 );
289 360 }
361 + if ( ( isset( $settings['tax_relation'] ) && 'AND' === $settings['tax_relation'] ) ||
362 + ( isset( $settings['relation'] ) && 'AND' === $settings['relation'] ) ) {
363 + add_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args_and' ], 10, 2 );
364 + }
365 +
366 + if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) {
367 + add_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args_outofstock' ] );
368 + }
290 369 }
291 370
292 371 /**
293 372 * Reset WooCommerce query arguments for product retrieval.
@@ -298,8 +377,113 @@
298 377 */
299 378 public static function reset_wc_query_args( $settings ) {
300 379 if ( ( isset( $settings['tax_relation'] ) && 'OR' === $settings['tax_relation'] ) ||
301 380 ( isset( $settings['relation'] ) && 'OR' === $settings['relation'] ) ) {
302 - remove_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args' ] );
381 + remove_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args_or' ] );
303 382 }
383 + if ( ( isset( $settings['tax_relation'] ) && 'AND' === $settings['tax_relation'] ) ||
384 + ( isset( $settings['relation'] ) && 'AND' === $settings['relation'] ) ) {
385 + remove_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args_and' ] );
386 + }
387 +
388 + if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) {
389 + remove_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args_outofstock' ] );
390 + }
391 + }
392 + /**
393 + * Display a filter header.
394 + *
395 + * @param array $settings The settings.
396 + *
397 + * @return void
398 + */
399 + public static function default_filter_header( $settings ) {
400 + if ( empty( $settings['show_filter_header'] ) && empty( $settings['filter_header_text'] ) ) {
401 + return;
402 + }
403 +
404 + $wrapper_class = 'rtsb-default-filter-header ';
405 +
406 + ?>
407 +
408 + <div class="<?php echo esc_attr( $wrapper_class ); ?>">
409 + <h3><?php echo esc_html( $settings['filter_header_text'] ); ?></h3>
410 + </div>
411 +
412 + <?php
413 + }
414 + /**
415 + * Display a filter search form.
416 + *
417 + * @param array $settings The settings.
418 + *
419 + * @return void
420 + */
421 + public static function default_filter_search( $settings ) {
422 + if ( empty( $settings['search_form'] ) ) {
423 + return;
424 + }
425 +
426 + $title = [
427 + 'title' => ! empty( $settings['search_title'] ) ? $settings['search_title'] : '',
428 + 'show_icon' => ! empty( $settings['show_search_title_icon'] ),
429 + 'icon' => ! empty( $settings['filter_search_title_icon'] ) ? $settings['filter_search_title_icon'] : [],
430 + ];
431 + $placeholder = ! empty( $settings['search_placeholder'] ) ? $settings['search_placeholder'] : '';
432 + $btn_icon = ! empty( $settings['search_title_icon'] ) ? $settings['search_title_icon'] : [];
433 + $wrapper_class = 'rtsb-default-filter-search rtsb-default-product-search';
434 + $unique_id = substr( uniqid(), -6 );
435 + $search_term = isset( $_REQUEST['s'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
436 + ?>
437 +
438 + <div class="<?php echo esc_attr( $wrapper_class ); ?>">
439 + <?php
440 + Fns::print_html( RenderHelpers::get_default_filter_title( $title ) );
441 + ?>
442 + <div class="default-search-content">
443 + <div class="woocommerce-product-search<?php echo ! empty( $search_term ) ? ' active' : ''; ?>">
444 + <div class="search-input">
445 + <label class="screen-reader-text" for="rtsb-product-default-search-form-<?php echo esc_attr( $unique_id ); ?>"><?php echo esc_html( $placeholder ); ?></label>
446 + <input type="search" id="rtsb-product-default-search-form-<?php echo esc_attr( $unique_id ); ?>" class="rtsb-default-search-field" placeholder="<?php echo esc_html( $placeholder ); ?>" value="<?php echo esc_attr( $search_term ); ?>" name="s" autocomplete="off">
447 + </div>
448 + <button class="rtsb-search-submit">
449 + <?php
450 +
451 + Fns::print_html( Fns::icons_manager( $btn_icon, 'search-icon' ) );
452 +
453 + ?>
454 + <span></span>
455 + </button>
456 + </div>
457 + </div>
458 + </div>
459 +
460 + <?php
461 + }
462 + /**
463 + * Query modifier.
464 + *
465 + * @param object $query Query.
466 + * @return object
467 + */
468 + public static function query_modifier( $query ) {
469 + $onsale_filter = isset( $_GET['sale_filter'] ) ? sanitize_text_field( wp_unslash( $_GET['sale_filter'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
470 + $on_sale_products = wc_get_product_ids_on_sale();
471 +
472 + if ( 'onsale' === $onsale_filter ) {
473 + $query->set( 'post__in', ! empty( $on_sale_products ) ? $on_sale_products : [ 0 ] );
474 + } elseif ( 'regular' === $onsale_filter ) {
475 + $query->set( 'post__not_in', $on_sale_products );
476 + }
477 +
478 + return $query;
479 + }
480 +
481 + /**
482 + * Delete cache when switching to another theme.
483 + *
484 + * @return void
485 + */
486 + public static function clear_cache() {
487 + Cache::clear_all_cache();
304 488 }
305 489 }