PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.10.0
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.10.0
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 / functions.php

functions.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 1.10.0, at inc/functions.php

257 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Essential functions.
5 *
6 * @package Merchant
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 /**
14 * Get template part.
15 *
16 */
17 function merchant_get_template_part( $folder_path = '', $name = '', $args = array(), $return_results = false ) {
18 if ( ! empty( $args ) && is_array( $args ) ) {
19 extract( $args );
20 }
21
22 $folder_path = ! empty( $folder_path ) ? "/$folder_path/" : '';
23
24 $template = '';
25
26 // Look in yourtheme/merchant/folder-path/name.php and yourtheme/merchant/folder-path/name.php.
27 if ( $name ) {
28 $template = locate_template( array( "merchant{$folder_path}{$name}.php" ) );
29 }
30
31 // Get default.
32 if ( ! $template && $name ) {
33 // Try to get it from the PRO dir if it exists.
34 if ( defined( 'MERCHANT_PRO_DIR' ) && file_exists( MERCHANT_PRO_DIR . "templates{$folder_path}{$name}.php" ) ) {
35 $template = MERCHANT_PRO_DIR . "templates{$folder_path}{$name}.php";
36 // Otherwise take it from the base dir.
37 } elseif ( file_exists( MERCHANT_DIR . "templates{$folder_path}{$name}.php" ) ) {
38 $template = MERCHANT_DIR . "templates{$folder_path}{$name}.php";
39 }
40 }
41
42 /**
43 * Hook: 'merchant_get_template_part'
44 *
45 * @since 1.0
46 */
47 $template = apply_filters( 'merchant_get_template_part', $template, $folder_path, $name );
48
49
50 if ( $template ) {
51 // Whether to return template HTML as string or to echo it
52 if ( $return_results ) {
53 ob_start();
54 include( $template );
55
56 return ob_get_clean();
57 }
58
59 return include( $template );
60 }
61 }
62
63 /**
64 * Check if Merchant Pro is installed and active.
65 *
66 * @return bool
67 */
68 if ( ! function_exists( 'merchant_is_pro_active' ) ) {
69 function merchant_is_pro_active() {
70 return defined( 'MERCHANT_PRO_VERSION' );
71 }
72 }
73
74 /**
75 * Check if Botiga theme is installed and active.
76 *
77 * @return bool
78 */
79 if ( ! function_exists( 'merchant_is_botiga_active' ) ) {
80 function merchant_is_botiga_active() {
81 return defined( 'BOTIGA_VERSION' );
82 }
83 }
84
85 /**
86 * Check if Divi theme is installed and active.
87 *
88 * @return bool
89 */
90 if ( ! function_exists( 'merchant_is_divi_active' ) ) {
91 function merchant_is_divi_active() {
92 return defined( 'ET_CORE_VERSION' );
93 }
94 }
95
96 /**
97 * Check if Avada theme is installed and active.
98 *
99 * @return bool
100 */
101 if ( ! function_exists( 'merchant_is_avada_active' ) ) {
102 function merchant_is_avada_active() {
103 return defined( 'AVADA_VERSION' );
104 }
105 }
106
107 /**
108 * Check if Kadence theme is installed and active.
109 *
110 * @return bool
111 */
112 if ( ! function_exists( 'merchant_is_kadence_active' ) ) {
113 function merchant_is_kadence_active() {
114 return class_exists( '\Kadence\Theme' );
115 }
116 }
117
118 /**
119 * Check if OceanWP theme is installed and active.
120 *
121 * @return bool
122 */
123 if ( ! function_exists( 'merchant_is_oceanwp_active' ) ) {
124 function merchant_is_oceanwp_active() {
125 return class_exists( 'OCEANWP_Theme_Class' );
126 }
127 }
128
129 /**
130 * Check if Blocksy theme is installed and active.
131 *
132 * @return bool
133 */
134 if ( ! function_exists( 'merchant_is_blocksy_active' ) ) {
135 function merchant_is_blocksy_active() {
136 return class_exists( 'Blocksy_Manager' );
137 }
138 }
139
140 /**
141 * Check if Flatsome theme is installed and active.
142 *
143 * @return bool
144 */
145 if ( ! function_exists( 'merchant_is_flatsome_active' ) ) {
146 function merchant_is_flatsome_active() {
147 return class_exists( 'Flatsome' );
148 }
149 }
150
151 /**
152 * Check if Astra theme or its Pro version is installed and active.
153 *
154 * @param $is_pro_active
155 *
156 * @return bool
157 */
158 if ( ! function_exists( 'merchant_is_astra_active' ) ) {
159 function merchant_is_astra_active( $is_pro_active = false ) {
160 if ( $is_pro_active ) {
161 return function_exists( 'astra_has_pro_woocommerce_addon' ) && astra_has_pro_woocommerce_addon();
162 }
163
164 return defined( 'ASTRA_THEME_VERSION' );
165 }
166 }
167
168 /**
169 * Check if WooCommerce Germanized theme is installed and active.
170 *
171 * @return bool
172 */
173 if ( ! function_exists( 'merchant_is_woocommerce_germanized_active' ) ) {
174 function merchant_is_woocommerce_germanized_active() {
175 return class_exists( 'WooCommerce_Germanized' );
176 }
177 }
178
179
180 /**
181 * Check if Breakdance Builder is installed and active.
182 *
183 * @return bool
184 */
185 if ( ! function_exists( 'merchant_is_breakdance_active' ) ) {
186 function merchant_is_breakdance_active() {
187 return defined( '__BREAKDANCE_VERSION' );
188 }
189 }
190
191 /**
192 * Check if Elementor or its Pro version is installed and active.
193 *
194 * @return bool
195 */
196 if ( ! function_exists( 'merchant_is_elementor_active' ) ) {
197 function merchant_is_elementor_active( $is_pro_active = false ) {
198 if ( $is_pro_active ) {
199 return defined( 'ELEMENTOR_PRO_VERSION' );
200 }
201
202 return defined( 'ELEMENTOR_VERSION' );
203 }
204 }
205
206 /**
207 * Check if any shortcode starts with merchant.
208 * If the shortcode is not registered, register it with return null to guarantee it exists.
209 */
210 if ( ! function_exists( 'merchant_modules_shortcode_exists' ) ) {
211 function merchant_modules_shortcode_exists() {
212 /**
213 * Filter the shortcodes.
214 *
215 * @param array $shortcodes modules shortcodes
216 *
217 * @since 1.8
218 */
219 $shortcodes = apply_filters( 'merchant_modules_shortcodes',
220 array(
221 'merchant_module_stock_scarcity',
222 'merchant_module_wait_list',
223 'merchant_module_volume_discounts',
224 'merchant_module_payment_logos',
225 'merchant_module_cart_reserved_timer',
226 'merchant_module_product_brand_image',
227 'merchant_module_size_chart',
228 'merchant_module_reasons_to_buy',
229 'merchant_module_recently_viewed_products',
230 'merchant_module_trust_badges',
231 'merchant_module_advanced_reviews',
232 'merchant_module_frequently_bought_together',
233 'merchant_module_buy_x_get_y',
234 'merchant_module_product_bundles',
235 'merchant_module_quick_social_links',
236 'merchant_module_product_navigation_links',
237 'merchant_module_product_video',
238 'merchant_module_product_audio',
239 'merchant_module_countdown_timer',
240 'merchant_module_product_labels',
241 'merchant_module_wishlist',
242 'merchant_module_clear_cart',
243 'merchant_module_free_shipping_progress_bar_single_product_page',
244 'merchant_module_free_shipping_progress_bar_cart_page',
245 'merchant_module_free_shipping_progress_bar_checkout_page',
246 )
247 );
248
249 // Loop through the shortcodes and register them if they don't exist.
250 array_map( static function ( $shortcode ) {
251 if ( ! shortcode_exists( $shortcode ) ) {
252 add_shortcode( $shortcode, '__return_null' );
253 }
254 }, $shortcodes );
255 }
256 }
257 add_action( 'init', 'merchant_modules_shortcode_exists' );