PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.10.3
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.10.3
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / inc / compatibility / class-merchant-elementor-builder.php

class-merchant-elementor-builder.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 1.10.3, at inc/compatibility/class-merchant-elementor-builder.php

236 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * Elementor Builder compatibility layer
9 */
10 if ( ! class_exists( 'Merchant_Elementor_Builder' ) ) {
11 class Merchant_Elementor_Builder {
12
13 /**
14 * Constructor.
15 */
16 public function __construct() {
17 if ( ( is_admin() && ! wp_doing_ajax() ) || ! merchant_is_elementor_active() ) {
18 return;
19 }
20
21 /**
22 * Elementor Pro Hook for Single Product Page when using Template
23 *
24 * Single Product Template works for Pro only
25 *
26 * Using `woocommerce_after_add_to_cart_form` as other hooks that use inside each module doesn't seem to be working.
27 */
28 add_action( 'elementor/theme/before_do_single', function( $locations_manager ) {
29
30 // Payment Logos
31 if ( Merchant_Modules::is_module_active( Merchant_Payment_Logos::MODULE_ID ) ) {
32 $pl = new Merchant_Payment_Logos();
33 add_action( 'woocommerce_after_add_to_cart_form', array( $pl, 'payment_logos_output' ), 15 );
34 }
35
36 // Trust Badges
37 if ( Merchant_Modules::is_module_active( Merchant_Trust_Badges::MODULE_ID ) ) {
38 $tb = new Merchant_Trust_Badges();
39 add_action( 'woocommerce_after_add_to_cart_form', array( $tb, 'trust_badges_output' ), 20 );
40 }
41
42 if ( merchant_is_pro_active() ) {
43
44 // Wishlist
45 if ( Merchant_Modules::is_module_active( Merchant_Wishlist::MODULE_ID ) ) {
46 // Display on single product.
47 $display_on_single_product = Merchant_Admin_Options::get( Merchant_Wishlist::MODULE_ID, 'display_on_single_product', true );
48 if ( $display_on_single_product ) {
49 $wishlist = new Merchant_Pro_Wishlist( Merchant_Modules::get_module( Merchant_Wishlist::MODULE_ID ) );;
50
51 add_action( 'woocommerce_after_add_to_cart_form', array( $wishlist, 'wishlist_link' ) );
52 //add_action( 'elementor/element/woocommerce-product-content/section_style/after_section_end', array( $wishlist, 'wishlist_link' ), 99 );
53 //add_action( 'elementor/element/woocommerce-product-meta/section_product_meta_style/after_section_end', array( $wishlist, 'wishlist_link' ) );
54 }
55 }
56
57 // Product Brand Image
58 if ( Merchant_Modules::is_module_active( Merchant_Product_Brand_Image::MODULE_ID ) ) {
59 $pbi = new Merchant_Pro_Product_Brand_Image( Merchant_Modules::get_module( Merchant_Product_Brand_Image::MODULE_ID ) );
60 add_action( 'woocommerce_after_add_to_cart_form', array( $pbi, 'brand_image' ), 25 );
61 }
62
63 // Product Navigation Links
64 if ( Merchant_Modules::is_module_active( Merchant_Product_Navigation_Links::MODULE_ID ) ) {
65 $pnl = new Merchant_Pro_Product_Navigation_Links( Merchant_Modules::get_module( Merchant_Product_Navigation_Links::MODULE_ID ) );
66 add_action( 'woocommerce_after_add_to_cart_form', array( $pnl, 'render_output_html' ), 100 );
67 }
68 }
69 } );
70
71 add_filter( 'merchant_enqueue_module_styles', array( $this, 'should_enqueue_styles' ), 10, 2 );
72 add_filter( 'merchant_enqueue_module_scripts', array( $this, 'should_enqueue_scripts' ), 10, 2 );
73
74 // Custom CSS.
75 add_filter( 'merchant_custom_css', array( $this, 'frontend_custom_css' ) );
76 }
77
78 /**
79 * Determines whether to enqueue styles for modules.
80 *
81 * @param $enqueue
82 * @param $module
83 *
84 * @return boolean
85 */
86 public function should_enqueue_styles( $enqueue, $module ) {
87 $module_id = $module->module_id ?? '';
88
89 if ( \Elementor\Plugin::$instance->preview->is_preview_mode() && Merchant_Modules::is_module_active( $module_id ) ) {
90 return true;
91 }
92
93 // Todo: check if required for other modules as well
94 if ( ! \Elementor\Plugin::$instance->preview->is_preview_mode() && Merchant_Modules::is_module_active( $module_id ) && ( $module_id === 'wishlist' ) ) {
95 global $post;
96
97 if ( empty( $post ) ) {
98 return $enqueue;
99 }
100
101 $elementor_data = get_post_meta( $post->ID, '_elementor_data', true );
102 if (
103 $elementor_data &&
104 ( strpos( $elementor_data, 'woocommerce-products' ) !== false || strpos( $elementor_data, 'wc-products' ) !== false ) ) {
105 return true;
106 }
107 }
108
109 return $enqueue;
110 }
111
112 /**
113 * Determines whether to enqueue scripts for modules.
114 *
115 * @param $enqueue
116 * @param $module
117 *
118 * @return mixed|true
119 */
120 public function should_enqueue_scripts( $enqueue, $module ) {
121 $module_id = $module->module_id ?? '';
122
123 if ( \Elementor\Plugin::$instance->preview->is_preview_mode() && Merchant_Modules::is_module_active( $module_id ) ) {
124 return true;
125 }
126
127 // Todo: check if required for other modules as well
128 if ( ! \Elementor\Plugin::$instance->preview->is_preview_mode() && Merchant_Modules::is_module_active( $module_id ) && ( $module_id === 'wishlist' ) ) {
129 global $post;
130
131 if ( empty( $post ) ) {
132 return $enqueue;
133 }
134
135 $elementor_data = get_post_meta( $post->ID, '_elementor_data', true );
136 if (
137 $elementor_data &&
138 ( strpos( $elementor_data, 'woocommerce-products' ) !== false || strpos( $elementor_data, 'wc-products' ) !== false ) ) {
139 return true;
140 }
141 }
142
143 return $enqueue;
144 }
145
146 /**
147 * Frontend custom CSS.
148 *
149 * @param string $css The custom CSS.
150 * @return string $css The custom CSS.
151 */
152 public function frontend_custom_css( $css ) {
153 $css .= Merchant_Floating_Mini_Cart::get_module_custom_css();
154
155 // Quick View
156 if ( Merchant_Modules::is_module_active( Merchant_Quick_View::MODULE_ID ) ) {
157 $css .= '
158 .merchant-quick-view-button {
159 padding: .618em 1em !important;
160 }
161 ';
162 }
163
164 // Payment Logos
165 if ( Merchant_Modules::is_module_active( Merchant_Payment_Logos::MODULE_ID ) ) {
166 $css .= '
167 .single-product li .merchant-payment-logos {
168 display: none !important;
169 }
170 ';
171 }
172
173 // Trust Badges
174 if ( Merchant_Modules::is_module_active( Merchant_Trust_Badges::MODULE_ID ) ) {
175 $css .= '
176 .single-product li .merchant-trust-badges {
177 display: none !important;
178 }
179 ';
180 }
181
182 if ( merchant_is_pro_active() ) {
183
184 // Variation Swatches
185 if ( Merchant_Modules::is_module_active( Merchant_Stock_Scarcity::MODULE_ID ) ) {
186 $css .= '
187 .single-product form.cart {
188 flex-wrap: wrap !important;
189 }
190 ';
191 }
192
193 // Wishlist
194 if ( Merchant_Modules::is_module_active( Merchant_Wishlist::MODULE_ID ) ) {
195 $css .= '
196 .single-product .merchant-wishlist-button {
197 position: static;
198 }
199 .single-product li .merchant-wishlist-button {
200 position: absolute;
201 }
202
203 .merchant-wishlist-button ~ .merchant-product-swatches .merchant-wishlist-button {
204 display: none !important;
205 }
206 ';
207 }
208
209 // Product Brand Image
210 if ( Merchant_Modules::is_module_active( Merchant_Product_Brand_Image::MODULE_ID ) ) {
211 $css .= '
212 .single-product li .merchant-product-brand-image {
213 display: none !important;
214 }
215 ';
216 }
217
218 // Product Navigation Links
219 if ( Merchant_Modules::is_module_active( Merchant_Product_Navigation_Links::MODULE_ID ) ) {
220 $css .= '
221 .single-product li .merchant-product-navigation {
222 display: none !important;
223 }
224 ';
225 }
226 }
227
228 return $css;
229 }
230 }
231
232 add_action( 'init', function() {
233 new Merchant_Elementor_Builder();
234 } );
235 }
236