PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.6.3
ShopBuilder – WooCommerce Builder For Elementor v2.6.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/Controllers/Hooks/ActionHooks.php +244 -20 2.1.42.6.3 View file →
@@ -6,8 +6,9 @@
6 6 */
7 7
8 8 namespace RadiusTheme\SB\Controllers\Hooks;
9 9
10 +use RadiusTheme\SB\Elementor\Helper\RenderHelpers;
10 11 use RadiusTheme\SB\Helpers\Fns;
11 12 use RadiusTheme\SB\Models\GeneralList;
12 13 use RadiusTheme\SB\Helpers\BuilderFns;
13 14 use RadiusTheme\SB\Models\TemplateSettings;
@@ -38,53 +39,180 @@
38 39 );
39 40 add_action( 'deleted_post', [ __CLASS__, 'deleted_post' ], 10, 2 );
40 41 add_action( 'rtsb/elements/render/before_query', [ __CLASS__, 'modify_wc_query_args' ] );
41 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 + }
42 95 }
96 +
97 +
43 98 /**
44 - * Meta tags for social sharing.
99 + * @param boolen $has_orders Order exist or not.
45 100 *
46 101 * @return void
47 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 + */
48 154 public static function deleted_post( $post_id, $post ) {
49 155 if ( BuilderFns::$post_type_tb !== $post->post_type ) {
50 156 return;
51 157 }
158 +
52 159 $options = BuilderFns::option_name_for_specific_product_set_default( $post_id );
160 + TemplateSettings::instance()->delete_option( $options );
53 161
54 - if ( TemplateSettings::instance()->get_option( $options ) ) {
55 - TemplateSettings::instance()->delete_option( $options );
56 - }
57 -
58 162 $template_options = BuilderFns::option_name_by_template_id( $post_id );
59 - if ( TemplateSettings::instance()->get_option( $template_options ) ) {
60 - TemplateSettings::instance()->delete_option( $template_options );
61 - }
163 + TemplateSettings::instance()->delete_option( $template_options );
62 164
63 165 $archive_options = BuilderFns::archive_option_name_by_template_id( $post_id );
64 - if ( TemplateSettings::instance()->get_option( $archive_options ) ) {
65 - TemplateSettings::instance()->delete_option( $archive_options );
66 - }
166 + TemplateSettings::instance()->delete_option( $archive_options );
67 167
68 168 $category_options = BuilderFns::option_name_for_specific_category_set_default( $post_id );
69 - if ( TemplateSettings::instance()->get_option( $category_options ) ) {
70 - TemplateSettings::instance()->delete_option( $category_options );
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 + }
71 184 }
185 + TemplateSettings::instance()->delete_option( $options_product_selected_cat );
72 186
73 - $selected_category_options = BuilderFns::archive_option_name_by_template_id( $post_id );
74 - if ( TemplateSettings::instance()->get_option( $selected_category_options ) ) {
75 - TemplateSettings::instance()->delete_option( $selected_category_options );
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 + }
76 200 }
201 + TemplateSettings::instance()->delete_option( $options_product_selected_tag );
77 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 +
78 207 global $wpdb;
79 - // Prepare and execute the SQL query.
208 + // Prepare and execute the SQL query.
80 209 $sql = $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %d", BuilderFns::$view_template_for_products_meta, $post_id );
81 - $wpdb->query( $sql );
210 + $wpdb->query( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching
82 211
83 212 // Prepare and execute the SQL query.
84 213 $sql = $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE meta_key = %s AND meta_value = %d", BuilderFns::$view_template_for_archive_meta, $post_id );
85 - $wpdb->query( $sql );
86 -
214 + $wpdb->query( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching
87 215 }
88 216 /**
89 217 * Meta tags for social sharing.
90 218 *
@@ -190,8 +318,12 @@
190 318 if ( ( isset( $settings['tax_relation'] ) && 'OR' === $settings['tax_relation'] ) ||
191 319 ( isset( $settings['relation'] ) && 'OR' === $settings['relation'] ) ) {
192 320 add_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args' ], 10, 2 );
193 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 + }
194 326 }
195 327
196 328 /**
197 329 * Reset WooCommerce query arguments for product retrieval.
@@ -204,6 +336,98 @@
204 336 if ( ( isset( $settings['tax_relation'] ) && 'OR' === $settings['tax_relation'] ) ||
205 337 ( isset( $settings['relation'] ) && 'OR' === $settings['relation'] ) ) {
206 338 remove_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args' ] );
207 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;
208 432 }
209 433 }