PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.1.7
ShopBuilder – WooCommerce Builder For Elementor v2.1.7
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.1.7, at app/Controllers/Hooks/ActionHooks.php

306 lines 10.9 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\Models\GeneralList;
12 use RadiusTheme\SB\Helpers\BuilderFns;
13 use RadiusTheme\SB\Models\TemplateSettings;
14 use RadiusTheme\SB\Elementor\Render\Render;
15
16 defined( 'ABSPATH' ) || exit();
17
18 /**
19 * Main ActionHooks class.
20 */
21 class ActionHooks {
22 /**
23 * Init Hooks.
24 *
25 * @return void
26 */
27 public static function init_hooks() {
28 add_action( 'wp_head', [ __CLASS__, 'og_metatags_for_sharing' ], 1 );
29 add_action( 'woocommerce_share', [ __CLASS__, 'shopbuilder_share' ], 20 );
30 add_action( 'rtsb/wcqv/product/summary', [ __CLASS__, 'shopbuilder_share' ], 40 );
31 add_action( 'rtsb/shop/product/image', [ __CLASS__, 'render_image' ], 10, 2 );
32
33 add_action(
34 'admin_init',
35 function () {
36 remove_post_type_support( BuilderFns::$post_type_tb, 'revisions' );
37 }
38 );
39 add_action( 'deleted_post', [ __CLASS__, 'deleted_post' ], 10, 2 );
40 add_action( 'rtsb/elements/render/before_query', [ __CLASS__, 'modify_wc_query_args' ] );
41 add_action( 'rtsb/elements/render/after_query', [ __CLASS__, 'reset_wc_query_args' ] );
42 // Cart Table.
43 remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );
44 add_action( 'woocommerce_cart_is_empty', [ __CLASS__, 'cart_is_empty' ], 10 );
45 /**
46 * Notices.
47 */
48 remove_action( 'woocommerce_cart_is_empty', 'woocommerce_output_all_notices', 5 );
49 remove_action( 'woocommerce_shortcode_before_product_cat_loop', 'woocommerce_output_all_notices', 10 );
50 remove_action( 'woocommerce_before_shop_loop', 'woocommerce_output_all_notices', 10 );
51 remove_action( 'woocommerce_before_single_product', 'woocommerce_output_all_notices', 10 );
52 remove_action( 'woocommerce_before_cart', 'woocommerce_output_all_notices', 10 );
53 remove_action( 'woocommerce_before_checkout_form_cart_notices', 'woocommerce_output_all_notices', 10 );
54 remove_action( 'woocommerce_before_checkout_form', 'woocommerce_output_all_notices', 10 );
55 remove_action( 'woocommerce_account_content', 'woocommerce_output_all_notices', 5 );
56 remove_action( 'woocommerce_before_customer_login_form', 'woocommerce_output_all_notices', 10 );
57 remove_action( 'woocommerce_before_lost_password_form', 'woocommerce_output_all_notices', 10 );
58 remove_action( 'before_woocommerce_pay', 'woocommerce_output_all_notices', 10 );
59 remove_action( 'woocommerce_before_reset_password_form', 'woocommerce_output_all_notices', 10 );
60
61 /**
62 * Notices.
63 */
64 // add_action( 'woocommerce_cart_is_empty', [ Fns::class, 'woocommerce_output_all_notices' ], 5 );
65 add_action( 'woocommerce_shortcode_before_product_cat_loop', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
66 add_action( 'woocommerce_before_shop_loop', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
67 add_action( 'woocommerce_before_single_product', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
68 add_action( 'woocommerce_before_cart', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
69 add_action( 'woocommerce_before_checkout_form_cart_notices', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
70 add_action( 'woocommerce_before_checkout_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
71 add_action( 'woocommerce_account_content', [ Fns::class, 'woocommerce_output_all_notices' ], 5 );
72 add_action( 'woocommerce_before_customer_login_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
73 add_action( 'woocommerce_before_lost_password_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
74 add_action( 'before_woocommerce_pay', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
75 add_action( 'woocommerce_before_reset_password_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 );
76
77 // Checkout Page.
78 remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_login_form', 10 );
79 remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
80 add_action( 'woocommerce_before_checkout_form', [ __CLASS__, 'woocommerce_checkout_login_form' ], 10 );
81 add_action( 'woocommerce_before_checkout_form', [ __CLASS__, 'woocommerce_checkout_coupon_form' ], 10 );
82 // My Account Order Page.
83 add_action( 'woocommerce_before_account_orders', [ __CLASS__, 'before_account_orders' ], 10 );
84 add_action( 'woocommerce_after_account_orders', [ __CLASS__, 'after_account_orders' ], 10 );
85 }
86
87
88 /**
89 * @param boolen $has_orders Order exist or not.
90 *
91 * @return void
92 */
93 public static function after_account_orders( $has_orders ) {
94 if ( ! $has_orders ) {
95 echo '</div>';
96 }
97 }
98
99 /**
100 * @param boolen $has_orders Order exist or not.
101 *
102 * @return void
103 */
104 public static function before_account_orders( $has_orders ) {
105 if ( ! $has_orders ) {
106 echo '<div class="rtsb-notice">';
107 }
108 }
109
110
111 /**
112 * @return void
113 */
114 public static function woocommerce_checkout_coupon_form() {
115 echo '<div class="rtsb-notice">';
116 woocommerce_checkout_coupon_form();
117 echo '</div>';
118 }
119
120 /**
121 * @return void
122 */
123 public static function woocommerce_checkout_login_form() {
124 echo '<div class="rtsb-notice">';
125 woocommerce_checkout_login_form();
126 echo '</div>';
127 }
128
129 /**
130 * @return void
131 */
132 public static function cart_is_empty() {
133 echo '<div class="rtsb-notice">';
134 wc_empty_cart_message();
135 echo '</div>';
136 }
137
138
139 /**
140 * @param int $post_id Post Ids.
141 * @param object $post Post Object.
142 *
143 * @return void
144 */
145 public static function deleted_post( $post_id, $post ) {
146 if ( BuilderFns::$post_type_tb !== $post->post_type ) {
147 return;
148 }
149 $options = BuilderFns::option_name_for_specific_product_set_default( $post_id );
150
151 if ( TemplateSettings::instance()->get_option( $options ) ) {
152 TemplateSettings::instance()->delete_option( $options );
153 }
154
155 $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 }
159
160 $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 }
164
165 $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 );
168 }
169
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 );
173 }
174
175 global $wpdb;
176 // Prepare and execute the SQL query.
177 $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 );
179
180 // Prepare and execute the SQL query.
181 $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 );
183 }
184 /**
185 * Meta tags for social sharing.
186 *
187 * @return void
188 */
189 public static function shopbuilder_share() {
190 $generalList = GeneralList::instance()->get_data();
191
192 if (
193 empty( $generalList['social_share']['share_platforms_to_product_page'] ) ||
194 'on' !== $generalList['social_share']['share_platforms_to_product_page'] ||
195 empty( $generalList['social_share']['share_platforms'] )
196 ) {
197 return;
198 }
199
200 $share_platforms = [];
201
202 foreach ( $generalList['social_share']['share_platforms'] as $value ) {
203 $share_platforms[ $value ] = [
204 'share_items' => $value,
205 'share_text' => ucwords( $value ),
206 ];
207 }
208
209 $settings['share_platforms'] = $share_platforms;
210 $settings['layout'] = ! empty( $generalList['social_share']['share_icon_layout'] ) ? $generalList['social_share']['share_icon_layout'] : 1;
211 $settings['show_share_icon'] = 1;
212
213 // TODO:: Implement Later ! empty( $generalList['social_share']['share_icon_show_to_product_page'] ) && 'on' === $generalList['social_share']['share_icon_show_to_product_page'];
214 Fns::print_html( Render::instance()->social_share_view( 'elementor/general/social-share', $settings ), true );
215 }
216
217 /**
218 * Meta tags for social sharing.
219 *
220 * @return void
221 */
222 public static function og_metatags_for_sharing() {
223 global $post;
224
225 if ( ! isset( $post ) ) {
226 return;
227 }
228
229 if ( ! is_singular( 'product' ) ) {
230 return;
231 }
232
233 Fns::print_html( '<meta property="og:url" content="' . get_the_permalink() . '" />', true );
234 Fns::print_html( '<meta property="og:type" content="article" />', true );
235 Fns::print_html( '<meta property="og:title" content="' . $post->post_title . '" />', true );
236 Fns::print_html( '<meta property="og:description" content="' . wp_trim_words( $post->post_content, 150 ) . '" />' );
237
238 $attachment = get_the_post_thumbnail_url();
239
240 if ( ! empty( $attachment ) ) {
241 Fns::print_html( '<meta property="og:image" content="' . $attachment . '" />', true );
242 }
243
244 Fns::print_html( '<meta property="og:site_name" content="' . get_bloginfo( 'name' ) . '" />', true );
245 Fns::print_html( '<meta name="twitter:card" content="summary" />', true );
246 }
247
248 /**
249 * Render image.
250 *
251 * @param array $args Image args.
252 * @param array $settings Settings array.
253 *
254 * @return void
255 */
256 public static function render_image( $args, $settings ) {
257 if ( $args['image_link'] ) {
258 $aria_label = esc_attr(
259 /* translators: Product Name */
260 sprintf( __( 'Image link for Product: %s', 'shopbuilder' ), $args['title'] )
261 );
262 ?>
263 <figure>
264 <a class="woocommerce-LoopProduct-link rtsb-img-link" href="<?php echo esc_url( $args['p_link'] ); ?>" aria-label="<?php echo esc_attr( $aria_label ); ?>">
265 <?php
266 Fns::get_product_image( $args['img_html'], $args['hover_img_html'] );
267 ?>
268 </a>
269 </figure>
270 <?php
271 } else {
272 echo '<figure class="rtsb-img-link">';
273 Fns::get_product_image( $args['img_html'], $args['hover_img_html'] );
274 echo '</figure>';
275 }
276 }
277
278 /**
279 * Modify WooCommerce query arguments for product retrieval.
280 *
281 * @param array $settings The settings array.
282 *
283 * @return void
284 */
285 public static function modify_wc_query_args( $settings ) {
286 if ( ( isset( $settings['tax_relation'] ) && 'OR' === $settings['tax_relation'] ) ||
287 ( isset( $settings['relation'] ) && 'OR' === $settings['relation'] ) ) {
288 add_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args' ], 10, 2 );
289 }
290 }
291
292 /**
293 * Reset WooCommerce query arguments for product retrieval.
294 *
295 * @param array $settings The settings array.
296 *
297 * @return void
298 */
299 public static function reset_wc_query_args( $settings ) {
300 if ( ( isset( $settings['tax_relation'] ) && 'OR' === $settings['tax_relation'] ) ||
301 ( isset( $settings['relation'] ) && 'OR' === $settings['relation'] ) ) {
302 remove_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args' ] );
303 }
304 }
305 }
306