PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.1.4
ShopBuilder – WooCommerce Builder For Elementor v3.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
shopbuilder / app / Controllers / Hooks / ActionHooks.php

ActionHooks.php in ShopBuilder – WooCommerce Builder For Elementor 3.1.4, at app/Controllers/Hooks/ActionHooks.php

477 lines 17.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Main ActionHooks class.
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Controllers\Hooks;
9
10 use RadiusTheme\SB\Helpers\Fns;
11 use RadiusTheme\SB\Helpers\Cache;
12 use RadiusTheme\SB\Models\GeneralList;
13 use RadiusTheme\SB\Helpers\BuilderFns;
14 use RadiusTheme\SB\Models\TemplateSettings;
15 use RadiusTheme\SB\Elementor\Render\Render;
16 use RadiusTheme\SB\Elementor\Helper\RenderHelpers;
17
18 defined( 'ABSPATH' ) || exit();
19
20 /**
21 * Main ActionHooks class.
22 */
23 class ActionHooks {
24 /**
25 * Init Hooks.
26 *
27 * @return void
28 */
29 public static function init_hooks() {
30 add_action( 'rtsb/before/save/options', [ __CLASS__, 'clear_cron_schedule' ], 10, 3 );
31 add_action( 'wp_head', [ __CLASS__, 'og_metatags_for_sharing' ], 1 );
32 add_action( 'woocommerce_share', [ __CLASS__, 'shopbuilder_share' ], 20 );
33 add_action( 'rtsb/wcqv/product/summary', [ __CLASS__, 'shopbuilder_share' ], 40 );
34 add_action( 'rtsb/shop/product/image', [ __CLASS__, 'render_image' ], 10, 2 );
35
36 add_action(
37 'admin_init',
38 function () {
39 remove_post_type_support( BuilderFns::$post_type_tb, 'revisions' );
40 }
41 );
42 add_action( 'deleted_post', [ __CLASS__, 'deleted_post' ], 10, 2 );
43 add_action( 'rtsb/elements/render/before_query', [ __CLASS__, 'modify_wc_query_args' ] );
44 add_action( 'rtsb/elements/render/after_query', [ __CLASS__, 'reset_wc_query_args' ] );
45 // Cart Table.
46 remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );
47 add_action( 'woocommerce_cart_is_empty', [ __CLASS__, 'cart_is_empty' ], 10 );
48 /**
49 * Notices.
50 */
51 remove_action( 'woocommerce_cart_is_empty', 'woocommerce_output_all_notices', 5 );
52 remove_action( 'woocommerce_shortcode_before_product_cat_loop', 'woocommerce_output_all_notices', 10 );
53 remove_action( 'woocommerce_before_shop_loop', 'woocommerce_output_all_notices', 10 );
54 remove_action( 'woocommerce_before_single_product', 'woocommerce_output_all_notices', 10 );
55 remove_action( 'woocommerce_before_cart', 'woocommerce_output_all_notices', 10 );
56 remove_action( 'woocommerce_before_checkout_form_cart_notices', 'woocommerce_output_all_notices', 10 );
57 remove_action( 'woocommerce_before_checkout_form', 'woocommerce_output_all_notices', 10 );
58 remove_action( 'woocommerce_account_content', 'woocommerce_output_all_notices', 5 );
59 remove_action( 'woocommerce_before_customer_login_form', 'woocommerce_output_all_notices', 10 );
60 remove_action( 'woocommerce_before_lost_password_form', 'woocommerce_output_all_notices', 10 );
61 remove_action( 'before_woocommerce_pay', 'woocommerce_output_all_notices', 10 );
62 remove_action( 'woocommerce_before_reset_password_form', 'woocommerce_output_all_notices', 10 );
63
64 /**
65 * Notices.
66 */
67 add_action( 'woocommerce_shortcode_before_product_cat_loop', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
68 add_action( 'woocommerce_before_shop_loop', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
69 add_action( 'woocommerce_before_single_product', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
70 add_action( 'woocommerce_before_cart', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
71 add_action( 'woocommerce_before_checkout_form_cart_notices', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
72 add_action( 'woocommerce_before_checkout_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
73 add_action( 'woocommerce_account_content', [ Fns::class, 'woocommerce_output_all_notices' ], 5 );
74 add_action( 'woocommerce_before_customer_login_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
75 add_action( 'woocommerce_before_lost_password_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
76 add_action( 'before_woocommerce_pay', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
77 add_action( 'woocommerce_before_reset_password_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
78
79 // Checkout Page.
80 remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_login_form', 10 );
81 remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
82 add_action( 'woocommerce_before_checkout_form', [ __CLASS__, 'woocommerce_checkout_login_form' ], 10 );
83 add_action( 'woocommerce_before_checkout_form', [ __CLASS__, 'woocommerce_checkout_coupon_form' ], 10 );
84 // My Account Order Page.
85 add_action( 'woocommerce_before_account_orders', [ __CLASS__, 'before_account_orders' ], 10 );
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' ] );
98 }
99 /**
100 * Handle custom option save event.
101 *
102 * @param string $section_id The section identifier.
103 * @param string $block_id The block identifier.
104 * @param array $rawOptions The raw options being saved.
105 */
106 public static function clear_cron_schedule( $section_id, $block_id, $rawOptions ) {
107 $schedule = [
108 'abandoned_cart_recovery' => [
109 'rtsb_abandoned_cart_recovery_action',
110 'rtsb_send_abandoned_cart_emails',
111 ],
112 'currency_switcher' => [
113 'update_exchange_rates_hourly',
114 ],
115 ];
116 if ( ! isset( $schedule[ $block_id ] ) ) {
117 return;
118 }
119 if ( ! isset( $rawOptions['active'] ) ) {
120 return;
121 }
122 if ( 'on' === $rawOptions['active'] ) {
123 return;
124 }
125 // CLear All Custom Schedule If module disabled.
126 foreach ( $schedule[ $block_id ] as $hook ) {
127 wp_clear_scheduled_hook( $hook );
128 }
129 }
130
131 /**
132 * @param boolen $has_orders Order exist or not.
133 *
134 * @return void
135 */
136 public static function after_account_orders( $has_orders ) {
137 if ( ! $has_orders ) {
138 echo '</div>';
139 }
140 }
141
142 /**
143 * @param boolen $has_orders Order exist or not.
144 *
145 * @return void
146 */
147 public static function before_account_orders( $has_orders ) {
148 if ( ! $has_orders ) {
149 echo '<div class="rtsb-notice">';
150 }
151 }
152
153
154 /**
155 * @return void
156 */
157 public static function woocommerce_checkout_coupon_form() {
158 echo '<div class="rtsb-notice">';
159 woocommerce_checkout_coupon_form();
160 echo '</div>';
161 }
162
163 /**
164 * @return void
165 */
166 public static function woocommerce_checkout_login_form() {
167 echo '<div class="rtsb-notice">';
168 woocommerce_checkout_login_form();
169 echo '</div>';
170 }
171
172 /**
173 * @return void
174 */
175 public static function cart_is_empty() {
176 echo '<div class="rtsb-notice">';
177 wc_empty_cart_message();
178 echo '</div>';
179 }
180
181 /**
182 * @param int $post_id Post Ids.
183 * @param object $post Post Object.
184 *
185 * @return void
186 */
187 public static function deleted_post( $post_id, $post ) {
188 if ( BuilderFns::$post_type_tb !== $post->post_type ) {
189 return;
190 }
191
192 $options = BuilderFns::option_name_for_specific_product_set_default( $post_id );
193 TemplateSettings::instance()->delete_option( $options );
194
195 $template_options = BuilderFns::option_name_by_template_id( $post_id );
196 TemplateSettings::instance()->delete_option( $template_options );
197
198 $archive_options = BuilderFns::archive_option_name_by_template_id( $post_id );
199 TemplateSettings::instance()->delete_option( $archive_options );
200
201 $category_options = BuilderFns::option_name_for_specific_category_set_default( $post_id );
202 TemplateSettings::instance()->delete_option( $category_options );
203
204 $selected_category_options = BuilderFns::archive_option_name_by_template_id( $post_id );
205 TemplateSettings::instance()->delete_option( $selected_category_options );
206
207 // Delete Data From Options.
208 $options_product_selected_cat = BuilderFns::option_name_product_page_selected_cat( $post_id );
209 $cat_list = TemplateSettings::instance()->get_option( $options_product_selected_cat );
210 if ( ! empty( $cat_list ) ) {
211 foreach ( $cat_list as $old_slug ) {
212 $OldcatList = get_term_by( 'slug', $old_slug, 'product_cat' );
213 if ( ! empty( $OldcatList ) && ! is_wp_error( $OldcatList ) ) {
214 delete_term_meta( $OldcatList->term_id, BuilderFns::$categories_product_page_template, $post_id );
215 }
216 }
217 }
218 TemplateSettings::instance()->delete_option( $options_product_selected_cat );
219
220 $set_default_option = BuilderFns::option_name_product_page_specific_cat_set_default( $post_id );
221 TemplateSettings::instance()->delete_option( $set_default_option );
222
223 // Tags Remove.
224 $options_product_selected_tag = BuilderFns::option_name_product_page_selected_tag( $post_id );
225 $tag_list = TemplateSettings::instance()->get_option( $options_product_selected_tag );
226 if ( ! empty( $tag_list ) ) {
227 foreach ( $tag_list as $old_slug ) {
228 $OldTagList = get_term_by( 'slug', $old_slug, 'product_tag' );
229 if ( ! empty( $OldTagList ) && ! is_wp_error( $OldTagList ) ) {
230 delete_term_meta( $OldTagList->term_id, BuilderFns::$tags_product_page_template, $post_id );
231 }
232 }
233 }
234 TemplateSettings::instance()->delete_option( $options_product_selected_tag );
235
236 // Tag Set Default Option.
237 $tag_set_default_option = BuilderFns::option_name_product_page_specific_tag_set_default( $post_id );
238 TemplateSettings::instance()->delete_option( $tag_set_default_option );
239
240 global $wpdb;
241 // Prepare and execute the SQL query.
242 $sql = $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %d", BuilderFns::$view_template_for_products_meta, $post_id );
243 $wpdb->query( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching
244
245 // Prepare and execute the SQL query.
246 $sql = $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE meta_key = %s AND meta_value = %d", BuilderFns::$view_template_for_archive_meta, $post_id );
247 $wpdb->query( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching
248 }
249 /**
250 * Meta tags for social sharing.
251 *
252 * @return void
253 */
254 public static function shopbuilder_share() {
255 $generalList = GeneralList::instance()->get_data();
256
257 if (
258 empty( $generalList['social_share']['share_platforms_to_product_page'] ) ||
259 'on' !== $generalList['social_share']['share_platforms_to_product_page'] ||
260 empty( $generalList['social_share']['share_platforms'] )
261 ) {
262 return;
263 }
264
265 $share_platforms = [];
266
267 foreach ( $generalList['social_share']['share_platforms'] as $value ) {
268 $share_platforms[ $value ] = [
269 'share_items' => $value,
270 'share_text' => ucwords( $value ),
271 ];
272 }
273
274 $settings['share_platforms'] = $share_platforms;
275 $settings['layout'] = ! empty( $generalList['social_share']['share_icon_layout'] ) ? $generalList['social_share']['share_icon_layout'] : 1;
276 $settings['show_share_icon'] = 1;
277
278 /**
279 * Implement Later ! empty( $generalList['social_share']['share_icon_show_to_product_page'] ) && 'on' === $generalList['social_share']['share_icon_show_to_product_page'];
280 */
281 Fns::print_html( Render::instance()->social_share_view( 'elementor/general/social-share', $settings ), true );
282 }
283
284 /**
285 * Meta tags for social sharing.
286 *
287 * @return void
288 */
289 public static function og_metatags_for_sharing() {
290 global $post;
291
292 if ( ! isset( $post ) ) {
293 return;
294 }
295
296 if ( ! is_singular( 'product' ) ) {
297 return;
298 }
299
300 Fns::print_html( '<meta property="og:url" content="' . get_the_permalink() . '" />', true );
301 Fns::print_html( '<meta property="og:type" content="article" />', true );
302 Fns::print_html( '<meta property="og:title" content="' . $post->post_title . '" />', true );
303 Fns::print_html( '<meta property="og:description" content="' . wp_trim_words( $post->post_content, 150 ) . '" />' );
304
305 $attachment = get_the_post_thumbnail_url();
306
307 if ( ! empty( $attachment ) ) {
308 Fns::print_html( '<meta property="og:image" content="' . $attachment . '" />', true );
309 }
310
311 Fns::print_html( '<meta property="og:site_name" content="' . get_bloginfo( 'name' ) . '" />', true );
312 Fns::print_html( '<meta name="twitter:card" content="summary" />', true );
313 }
314
315 /**
316 * Render image.
317 *
318 * @param array $args Image args.
319 *
320 * @return void
321 */
322 public static function render_image( $args ) {
323 if ( $args['image_link'] ) {
324 $aria_label = esc_attr(
325 /* translators: Product Name */
326 sprintf( __( 'Image link for Product: %s', 'shopbuilder' ), $args['title'] )
327 );
328 ?>
329 <figure>
330 <a class="woocommerce-LoopProduct-link rtsb-img-link" href="<?php echo esc_url( $args['p_link'] ); ?>" aria-label="<?php echo esc_attr( $aria_label ); ?>">
331 <?php
332 Fns::get_product_image( $args['img_html'], $args['hover_img_html'] );
333 ?>
334 </a>
335 </figure>
336 <?php
337 } else {
338 echo '<figure class="rtsb-img-link">';
339 Fns::get_product_image( $args['img_html'], $args['hover_img_html'] );
340 echo '</figure>';
341 }
342 }
343
344 /**
345 * Modify WooCommerce query arguments for product retrieval.
346 *
347 * @param array $settings The settings array.
348 *
349 * @return void
350 */
351 public static function modify_wc_query_args( $settings ) {
352 if ( ( isset( $settings['tax_relation'] ) && 'OR' === $settings['tax_relation'] ) ||
353 ( isset( $settings['relation'] ) && 'OR' === $settings['relation'] ) ) {
354 add_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args' ], 10, 2 );
355 }
356
357 if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) {
358 add_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args_outofstock' ] );
359 }
360 }
361
362 /**
363 * Reset WooCommerce query arguments for product retrieval.
364 *
365 * @param array $settings The settings array.
366 *
367 * @return void
368 */
369 public static function reset_wc_query_args( $settings ) {
370 if ( ( isset( $settings['tax_relation'] ) && 'OR' === $settings['tax_relation'] ) ||
371 ( isset( $settings['relation'] ) && 'OR' === $settings['relation'] ) ) {
372 remove_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args' ] );
373 }
374
375 if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) {
376 remove_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args_outofstock' ] );
377 }
378 }
379 /**
380 * Display a filter header.
381 *
382 * @param array $settings The settings.
383 *
384 * @return void
385 */
386 public static function default_filter_header( $settings ) {
387 if ( empty( $settings['show_filter_header'] ) && empty( $settings['filter_header_text'] ) ) {
388 return;
389 }
390
391 $wrapper_class = 'rtsb-default-filter-header ';
392
393 ?>
394
395 <div class="<?php echo esc_attr( $wrapper_class ); ?>">
396 <h3><?php echo esc_html( $settings['filter_header_text'] ); ?></h3>
397 </div>
398
399 <?php
400 }
401 /**
402 * Display a filter search form.
403 *
404 * @param array $settings The settings.
405 *
406 * @return void
407 */
408 public static function default_filter_search( $settings ) {
409 if ( empty( $settings['search_form'] ) ) {
410 return;
411 }
412
413 $title = [
414 'title' => ! empty( $settings['search_title'] ) ? $settings['search_title'] : '',
415 'show_icon' => ! empty( $settings['show_search_title_icon'] ),
416 'icon' => ! empty( $settings['filter_search_title_icon'] ) ? $settings['filter_search_title_icon'] : [],
417 ];
418 $placeholder = ! empty( $settings['search_placeholder'] ) ? $settings['search_placeholder'] : '';
419 $btn_icon = ! empty( $settings['search_title_icon'] ) ? $settings['search_title_icon'] : [];
420 $wrapper_class = 'rtsb-default-filter-search rtsb-default-product-search';
421 $unique_id = substr( uniqid(), -6 );
422 $search_term = isset( $_REQUEST['s'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
423 ?>
424
425 <div class="<?php echo esc_attr( $wrapper_class ); ?>">
426 <?php
427 Fns::print_html( RenderHelpers::get_default_filter_title( $title ) );
428 ?>
429 <div class="default-search-content">
430 <div class="woocommerce-product-search<?php echo ! empty( $search_term ) ? ' active' : ''; ?>">
431 <div class="search-input">
432 <label class="screen-reader-text" for="rtsb-product-default-search-form-<?php echo esc_attr( $unique_id ); ?>"><?php echo esc_html( $placeholder ); ?></label>
433 <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">
434 </div>
435 <button class="rtsb-search-submit">
436 <?php
437
438 Fns::print_html( Fns::icons_manager( $btn_icon, 'search-icon' ) );
439
440 ?>
441 <span></span>
442 </button>
443 </div>
444 </div>
445 </div>
446
447 <?php
448 }
449 /**
450 * Query modifier.
451 *
452 * @param object $query Query.
453 * @return object
454 */
455 public static function query_modifier( $query ) {
456 $onsale_filter = isset( $_GET['sale_filter'] ) ? sanitize_text_field( wp_unslash( $_GET['sale_filter'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
457 $on_sale_products = wc_get_product_ids_on_sale();
458
459 if ( 'onsale' === $onsale_filter ) {
460 $query->set( 'post__in', ! empty( $on_sale_products ) ? $on_sale_products : [ 0 ] );
461 } elseif ( 'regular' === $onsale_filter ) {
462 $query->set( 'post__not_in', $on_sale_products );
463 }
464
465 return $query;
466 }
467
468 /**
469 * Delete cache when switching to another theme.
470 *
471 * @return void
472 */
473 public static function clear_cache() {
474 Cache::clear_all_cache();
475 }
476 }
477