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

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

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