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

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

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