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 5.2.0-beta.1 10.0.2 5.2.0-rc.1 10.0.3 5.2.0-rc.2 10.0.4 5.2.1 10.0.5 5.2.2 10.0.6 5.2.3 10.1.0 5.2.4 10.1.0-rc.1 5.2.5 10.1.0-rc.2 5.3.0 10.1.0-rc.3 5.3.0-beta.1 10.1.0-rc.4 5.3.0-rc.1 10.1.1 5.3.0-rc.2 10.1.2 5.3.1 10.1.3 5.3.2 10.1.4 5.3.3 10.2.0 5.4.0 10.2.0-beta.1 5.4.0-beta.1 10.2.0-beta.2 5.4.0-rc.1 10.2.0-rc.1 5.4.1 10.2.1 5.4.2 10.2.2 5.4.3 10.2.3 5.4.4 10.2.4 5.4.5 10.3.0 5.5.0 10.3.0-beta.1 5.5.0-beta.1 10.3.0-beta.2 5.5.0-rc.1 10.3.0-rc.1 5.5.0-rc.2 10.3.0-rc.2 5.5.1 10.3.1 5.5.2 10.3.2 5.5.3 10.3.3 5.5.4 10.3.4 5.5.5 10.3.5 5.6.0 10.3.6 5.6.0-beta.1 10.3.7 5.6.0-rc.1 10.3.8 5.6.0-rc.2 10.4.0 5.6.1 10.4.0-beta.1 5.6.2 10.4.0-beta.2 5.6.3 10.4.0-rc.1 5.7.0 10.4.1 5.7.0-beta.1 10.4.2 5.7.0-rc.1 10.4.3 5.7.1 10.4.4 5.7.2 10.5.0 5.7.3 10.5.0-beta.1 5.8.0 10.5.0-beta.2 5.8.0-beta.1 10.5.0-rc.1 5.8.0-beta.2 10.5.0-rc.2 5.8.0-rc.1 10.5.0-rc.3 5.8.1 10.5.1 5.8.2 10.5.2 5.9.0 10.5.3 5.9.0-beta.1 10.6.0 5.9.0-rc.1 10.6.0-beta.1 5.9.0-rc.2 10.6.0-beta.2 5.9.1 10.6.0-rc.1 5.9.2 10.6.1 6.0.0 10.6.2 6.0.0-beta.1 10.7.0 6.0.0-rc.1 10.7.0-beta.1 6.0.1 10.7.0-beta.2 6.0.2 10.7.0-rc.1 6.1.0 3.0.0 6.1.0-beta.1 3.0.1 6.1.0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7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / wc-conditional-functions.php
woocommerce / includes Last commit date
abstracts 4 days ago admin 4 days ago blocks 1 month ago cli 2 weeks ago customizer 6 months ago data-stores 4 days ago emails 2 weeks ago export 2 weeks ago gateways 2 weeks ago import 1 week ago integrations 1 month ago interfaces 6 months ago legacy 1 month ago libraries 2 weeks ago log-handlers 1 year ago payment-tokens 6 years ago product-usage 1 year ago queue 6 months ago react-admin 1 week ago rest-api 1 day ago shipping 5 months ago shortcodes 2 weeks ago theme-support 2 years ago tracks 2 weeks ago traits 5 years ago walkers 5 years ago wccom-site 2 months ago widgets 1 month ago class-wc-ajax.php 1 day ago class-wc-auth.php 2 years ago class-wc-autoloader.php 10 months ago class-wc-background-emailer.php 3 months ago class-wc-background-updater.php 6 years ago class-wc-brands-brand-settings-manager.php 1 year ago class-wc-brands-coupons.php 1 year ago class-wc-brands.php 2 weeks ago class-wc-breadcrumb.php 6 months ago class-wc-cache-helper.php 2 months ago class-wc-cart-fees.php 2 years ago class-wc-cart-session.php 2 weeks ago class-wc-cart-totals.php 1 year ago class-wc-cart.php 1 month ago class-wc-checkout.php 1 month ago class-wc-cli.php 2 weeks ago class-wc-comments.php 1 week ago class-wc-countries.php 3 months ago class-wc-coupon.php 2 weeks ago class-wc-customer-download-log.php 6 years ago class-wc-customer-download.php 2 years ago class-wc-customer.php 1 month ago class-wc-data-exception.php 8 years ago class-wc-data-store.php 3 years ago class-wc-datetime.php 4 years ago class-wc-deprecated-action-hooks.php 2 years ago class-wc-deprecated-filter-hooks.php 5 months ago class-wc-discounts.php 2 weeks ago class-wc-download-handler.php 2 weeks ago class-wc-emails.php 1 month ago class-wc-embed.php 3 weeks ago class-wc-form-handler.php 2 weeks ago class-wc-frontend-scripts.php 1 month ago class-wc-geo-ip.php 10 months ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 2 weeks ago class-wc-https.php 3 years ago class-wc-install.php 1 week ago class-wc-integrations.php 6 years ago class-wc-log-levels.php 2 years ago class-wc-logger.php 6 months ago class-wc-meta-data.php 2 months ago class-wc-order-factory.php 3 months ago class-wc-order-item-coupon.php 4 years ago class-wc-order-item-fee.php 2 weeks ago class-wc-order-item-meta.php 4 years ago class-wc-order-item-product.php 2 weeks ago class-wc-order-item-shipping.php 7 months ago class-wc-order-item-tax.php 2 months ago class-wc-order-item.php 1 month ago class-wc-order-query.php 2 months ago class-wc-order-refund.php 1 year ago class-wc-order.php 1 month ago class-wc-payment-gateways.php 2 weeks ago class-wc-payment-tokens.php 3 years ago class-wc-post-data.php 1 month ago class-wc-post-types.php 2 weeks ago class-wc-privacy-background-process.php 1 year ago class-wc-privacy-erasers.php 1 year ago class-wc-privacy-exporters.php 5 years ago class-wc-privacy.php 1 year ago class-wc-product-attribute.php 6 months ago class-wc-product-download.php 1 month ago class-wc-product-external.php 1 year ago class-wc-product-factory.php 5 months ago class-wc-product-grouped.php 1 month ago class-wc-product-query.php 6 months ago class-wc-product-simple.php 1 year ago class-wc-product-variable.php 1 week ago class-wc-product-variation.php 2 weeks ago class-wc-query.php 1 month ago class-wc-rate-limiter.php 4 years ago class-wc-regenerate-images-request.php 2 weeks ago class-wc-regenerate-images.php 2 weeks ago class-wc-register-wp-admin-settings.php 5 years ago class-wc-rest-authentication.php 1 day ago class-wc-rest-exception.php 5 years ago class-wc-session-handler.php 3 weeks ago class-wc-shipping-rate.php 1 year ago class-wc-shipping-zone.php 5 years ago class-wc-shipping-zones.php 2 weeks ago class-wc-shipping.php 1 month ago class-wc-shortcodes.php 2 weeks ago class-wc-structured-data.php 2 weeks ago class-wc-tax.php 1 month ago class-wc-template-loader.php 9 months ago class-wc-tracker.php 1 month ago class-wc-validation.php 1 month ago class-wc-webhook.php 2 weeks ago class-woocommerce.php 1 day ago wc-account-functions.php 2 months ago wc-attribute-functions.php 1 month ago wc-brands-functions.php 1 year ago wc-cart-functions.php 2 weeks ago wc-conditional-functions.php 2 weeks ago wc-core-functions.php 2 weeks ago wc-coupon-functions.php 7 months ago wc-deprecated-functions.php 2 weeks ago wc-formatting-functions.php 2 weeks ago wc-interactivity-api-functions.php 3 months ago wc-notice-functions.php 7 months ago wc-order-functions.php 2 weeks ago wc-order-item-functions.php 3 years ago wc-order-step-logger-functions.php 3 weeks ago wc-page-functions.php 1 month ago wc-product-functions.php 2 weeks ago wc-rest-functions.php 9 months ago wc-stock-functions.php 1 month ago wc-template-functions.php 1 week ago wc-template-hooks.php 1 year ago wc-term-functions.php 2 weeks ago wc-update-functions.php 1 week ago wc-user-functions.php 1 month ago wc-webhook-functions.php 2 months ago wc-widget-functions.php 6 years ago
wc-conditional-functions.php
631 lines
1 <?php
2 /**
3 * WooCommerce Conditional Functions
4 *
5 * Functions for determining the current query/page.
6 *
7 * Note that the query-dependent conditional functions are only reliable
8 * once the main query has been set up, that is, on or after the "wp" action hook.
9 * If used before that, they won't trigger any error or warning: they will simply
10 * return false, even if the condition they check for would be met later in the request.
11 *
12 * @package WooCommerce\Functions
13 * @version 2.3.0
14 */
15
16 use Automattic\Jetpack\Constants;
17 use Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils;
18
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22
23 /**
24 * Is_woocommerce - Returns true if on a page which uses WooCommerce templates (cart and checkout are standard pages with shortcodes and thus are not included).
25 *
26 * @return bool
27 */
28 function is_woocommerce() {
29 return apply_filters( 'is_woocommerce', is_shop() || is_product_taxonomy() || is_product() );
30 }
31
32 if ( ! function_exists( 'is_shop' ) ) {
33
34 /**
35 * Is_shop - Returns true when viewing the product type archive (shop).
36 *
37 * @return bool
38 */
39 function is_shop() {
40 return ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) );
41 }
42 }
43
44 if ( ! function_exists( 'is_product_taxonomy' ) ) {
45
46 /**
47 * Is_product_taxonomy - Returns true when viewing a product taxonomy archive.
48 *
49 * @return bool
50 */
51 function is_product_taxonomy() {
52 return is_tax( get_object_taxonomies( 'product' ) );
53 }
54 }
55
56 if ( ! function_exists( 'is_product_category' ) ) {
57
58 /**
59 * Is_product_category - Returns true when viewing a product category.
60 *
61 * @param string $term (default: '') The term slug your checking for. Leave blank to return true on any.
62 * @return bool
63 */
64 function is_product_category( $term = '' ) {
65 return is_tax( 'product_cat', $term );
66 }
67 }
68
69 if ( ! function_exists( 'is_product_tag' ) ) {
70
71 /**
72 * Is_product_tag - Returns true when viewing a product tag.
73 *
74 * @param string $term (default: '') The term slug your checking for. Leave blank to return true on any.
75 * @return bool
76 */
77 function is_product_tag( $term = '' ) {
78 return is_tax( 'product_tag', $term );
79 }
80 }
81
82 if ( ! function_exists( 'is_product' ) ) {
83
84 /**
85 * Is_product - Returns true when viewing a single product.
86 *
87 * @return bool
88 */
89 function is_product() {
90 return is_singular( array( 'product' ) );
91 }
92 }
93
94 if ( ! function_exists( 'is_cart' ) ) {
95
96 /**
97 * Is_cart - Returns true when viewing the cart page.
98 *
99 * @return bool
100 */
101 function is_cart() {
102 /**
103 * Filter to allow for custom logic to determine if the cart page is being viewed.
104 *
105 * @since 2.4.0
106 * @param bool $is_cart Whether the cart page is being viewed.
107 */
108 return apply_filters( 'woocommerce_is_cart', false ) || Constants::is_defined( 'WOOCOMMERCE_CART' ) || CartCheckoutUtils::is_cart_page();
109 }
110 }
111
112 if ( ! function_exists( 'is_checkout' ) ) {
113
114 /**
115 * Is_checkout - Returns true when viewing the checkout page, or when processing AJAX requests for updating or processing the checkout.
116 *
117 * @return bool
118 */
119 function is_checkout() {
120 /**
121 * Filter to allow for custom logic to determine if the checkout page is being viewed.
122 *
123 * @since 2.4.0
124 * @param bool $is_checkout Whether the checkout page is being viewed.
125 */
126 return apply_filters( 'woocommerce_is_checkout', false ) || Constants::is_defined( 'WOOCOMMERCE_CHECKOUT' ) || CartCheckoutUtils::is_checkout_page();
127 }
128 }
129
130 if ( ! function_exists( 'is_checkout_pay_page' ) ) {
131
132 /**
133 * Is_checkout_pay - Returns true when viewing the checkout's pay page (aka pay for order page).
134 *
135 * @param bool $use_query_params Whether to use query parameters to determine if this is the pay for order page.
136 * @return bool
137 */
138 function is_checkout_pay_page( bool $use_query_params = false ): bool {
139 global $wp;
140
141 // Use-case: attempt to identify the page based on global variables.
142 if ( ! empty( $wp->query_vars['order-pay'] ) && is_checkout() ) {
143 return true;
144 }
145
146 // Use-case: check for the presence of a specific query parameter when globals are not available.
147 if ( $use_query_params ) {
148 return isset( $_GET['pay_for_order'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
149 }
150
151 return false;
152 }
153 }
154
155 if ( ! function_exists( 'is_wc_endpoint_url' ) ) {
156
157 /**
158 * Is_wc_endpoint_url - Check if an endpoint is showing.
159 *
160 * @param string|false $endpoint Whether endpoint.
161 * @return bool
162 */
163 function is_wc_endpoint_url( $endpoint = false ) {
164 global $wp;
165
166 $wc_endpoints = WC()->query->get_query_vars();
167
168 if ( false !== $endpoint ) {
169 if ( ! isset( $wc_endpoints[ $endpoint ] ) ) {
170 return false;
171 } else {
172 $endpoint_var = $wc_endpoints[ $endpoint ];
173 }
174
175 return isset( $wp->query_vars[ $endpoint_var ] );
176 } else {
177 foreach ( $wc_endpoints as $key => $value ) {
178 if ( isset( $wp->query_vars[ $key ] ) ) {
179 return true;
180 }
181 }
182
183 return false;
184 }
185 }
186 }
187
188 if ( ! function_exists( 'is_account_page' ) ) {
189
190 /**
191 * Is_account_page - Returns true when viewing an account page.
192 *
193 * @return bool
194 */
195 function is_account_page() {
196 $page_id = wc_get_page_id( 'myaccount' );
197
198 return ( $page_id && is_page( $page_id ) ) || wc_post_content_has_shortcode( 'woocommerce_my_account' ) || apply_filters( 'woocommerce_is_account_page', false );
199 }
200 }
201
202 if ( ! function_exists( 'is_view_order_page' ) ) {
203
204 /**
205 * Is_view_order_page - Returns true when on the view order page.
206 *
207 * @return bool
208 */
209 function is_view_order_page() {
210 global $wp;
211
212 $page_id = wc_get_page_id( 'myaccount' );
213
214 return ( $page_id && is_page( $page_id ) && isset( $wp->query_vars['view-order'] ) );
215 }
216 }
217
218 if ( ! function_exists( 'is_edit_account_page' ) ) {
219
220 /**
221 * Check for edit account page.
222 * Returns true when viewing the edit account page.
223 *
224 * @since 2.5.1
225 * @return bool
226 */
227 function is_edit_account_page() {
228 global $wp;
229
230 $page_id = wc_get_page_id( 'myaccount' );
231
232 return ( $page_id && is_page( $page_id ) && isset( $wp->query_vars['edit-account'] ) );
233 }
234 }
235
236 if ( ! function_exists( 'is_order_received_page' ) ) {
237
238 /**
239 * Is_order_received_page - Returns true when viewing the order received page.
240 *
241 * @return bool
242 */
243 function is_order_received_page() {
244 global $wp;
245
246 $page_id = wc_get_page_id( 'checkout' );
247
248 return apply_filters( 'woocommerce_is_order_received_page', ( $page_id && is_page( $page_id ) && isset( $wp->query_vars['order-received'] ) ) );
249 }
250 }
251
252 if ( ! function_exists( 'is_payment_methods_page' ) ) {
253
254 /**
255 * Is_payment_methods_page - Returns true when viewing the payment methods list page.
256 *
257 * @return bool
258 */
259 function is_payment_methods_page() {
260 global $wp;
261
262 $page_id = wc_get_page_id( 'myaccount' );
263
264 return ( $page_id && is_page( $page_id ) && isset( $wp->query_vars['payment-methods'] ) );
265 }
266 }
267
268 if ( ! function_exists( 'is_add_payment_method_page' ) ) {
269
270 /**
271 * Is_add_payment_method_page - Returns true when viewing the add payment method page.
272 *
273 * @return bool
274 */
275 function is_add_payment_method_page() {
276 global $wp;
277
278 $page_id = wc_get_page_id( 'myaccount' );
279
280 return ( $page_id && is_page( $page_id ) && ( isset( $wp->query_vars['payment-methods'] ) || isset( $wp->query_vars['add-payment-method'] ) ) );
281 }
282 }
283
284 if ( ! function_exists( 'is_lost_password_page' ) ) {
285
286 /**
287 * Is_lost_password_page - Returns true when viewing the lost password page.
288 *
289 * @return bool
290 */
291 function is_lost_password_page() {
292 global $wp;
293
294 $page_id = wc_get_page_id( 'myaccount' );
295
296 return ( $page_id && is_page( $page_id ) && isset( $wp->query_vars['lost-password'] ) );
297 }
298 }
299
300 if ( ! function_exists( 'is_wc_admin_settings_page' ) ) {
301
302 /**
303 * Is_wc_admin_settings_page - Returns true when viewing the admin settings page.
304 *
305 * @return bool
306 */
307 function is_wc_admin_settings_page(): bool {
308 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
309 return isset( $_REQUEST['page'] ) && 'wc-settings' === wp_unslash( $_REQUEST['page'] ) && is_admin();
310 }
311 }
312
313 if ( ! function_exists( 'is_ajax' ) ) {
314
315 /**
316 * Is_ajax - Returns true when the page is loaded via ajax.
317 *
318 * @see wp_doing_ajax() for an equivalent function provided by WordPress since 4.7.0
319 * @return bool
320 */
321 function is_ajax() {
322 return function_exists( 'wp_doing_ajax' ) ? wp_doing_ajax() : Constants::is_defined( 'DOING_AJAX' );
323 }
324 }
325
326 if ( ! function_exists( 'is_store_notice_showing' ) ) {
327
328 /**
329 * Is_store_notice_showing - Returns true when store notice is active.
330 *
331 * @return bool
332 */
333 function is_store_notice_showing() {
334 return 'no' !== get_option( 'woocommerce_demo_store', 'no' );
335 }
336 }
337
338 if ( ! function_exists( 'is_filtered' ) ) {
339
340 /**
341 * Is_filtered - Returns true when filtering products using layered nav or price sliders.
342 *
343 * @return bool
344 */
345 function is_filtered() {
346 return apply_filters( 'woocommerce_is_filtered', ( count( WC_Query::get_layered_nav_chosen_attributes() ) > 0 || isset( $_GET['max_price'] ) || isset( $_GET['min_price'] ) || isset( $_GET['rating_filter'] ) ) ); // WPCS: CSRF ok.
347 }
348 }
349
350 if ( ! function_exists( 'taxonomy_is_product_attribute' ) ) {
351
352 /**
353 * Returns true when the passed taxonomy name is a product attribute.
354 *
355 * @uses $wc_product_attributes global which stores taxonomy names upon registration
356 * @param string $name of the attribute.
357 * @return bool
358 */
359 function taxonomy_is_product_attribute( $name ) {
360 global $wc_product_attributes;
361
362 return taxonomy_exists( $name ) && array_key_exists( $name, (array) $wc_product_attributes );
363 }
364 }
365
366 if ( ! function_exists( 'meta_is_product_attribute' ) ) {
367
368 /**
369 * Returns true when the passed meta name is a product attribute.
370 *
371 * @param string $name of the attribute.
372 * @param string $value of the attribute.
373 * @param int $product_id to check for attribute.
374 * @return bool
375 */
376 function meta_is_product_attribute( $name, $value, $product_id ) {
377 $product = wc_get_product( $product_id );
378
379 if ( $product && method_exists( $product, 'get_variation_attributes' ) ) {
380 $variation_attributes = $product->get_variation_attributes();
381 $attributes = $product->get_attributes();
382
383 return (
384 in_array( $name, array_keys( $attributes ), true ) &&
385 isset( $variation_attributes[ $attributes[ $name ]['name'] ] ) &&
386 in_array( $value, $variation_attributes[ $attributes[ $name ]['name'] ], true )
387 );
388 } else {
389 return false;
390 }
391 }
392 }
393
394 if ( ! function_exists( 'wc_tax_enabled' ) ) {
395
396 /**
397 * Are store-wide taxes enabled?
398 *
399 * @return bool
400 */
401 function wc_tax_enabled() {
402 return apply_filters( 'wc_tax_enabled', get_option( 'woocommerce_calc_taxes' ) === 'yes' );
403 }
404 }
405
406 if ( ! function_exists( 'wc_shipping_enabled' ) ) {
407
408 /**
409 * Is shipping enabled?
410 *
411 * @return bool
412 */
413 function wc_shipping_enabled() {
414 return apply_filters( 'wc_shipping_enabled', get_option( 'woocommerce_ship_to_countries' ) !== 'disabled' );
415 }
416 }
417
418 if ( ! function_exists( 'wc_prices_include_tax' ) ) {
419
420 /**
421 * Are prices inclusive of tax?
422 *
423 * @return bool
424 */
425 function wc_prices_include_tax() {
426 return wc_tax_enabled() && apply_filters( 'woocommerce_prices_include_tax', get_option( 'woocommerce_prices_include_tax' ) === 'yes' );
427 }
428 }
429
430 /**
431 * Simple check for validating a URL, it must start with http:// or https://.
432 * and pass FILTER_VALIDATE_URL validation.
433 *
434 * @param string $url to check.
435 * @return bool
436 */
437 function wc_is_valid_url( $url ) {
438
439 // Must start with http:// or https://.
440 if ( 0 !== strpos( $url, 'http://' ) && 0 !== strpos( $url, 'https://' ) ) {
441 return false;
442 }
443
444 // Must pass validation.
445 if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) {
446 return false;
447 }
448
449 return true;
450 }
451
452 /**
453 * Check if the home URL is https. If it is, we don't need to do things such as 'force ssl'.
454 *
455 * @since 2.4.13
456 * @return bool
457 */
458 function wc_site_is_https() {
459 return false !== strstr( get_option( 'home' ), 'https:' );
460 }
461
462 /**
463 * Check if the checkout is configured for https. Look at options, WP HTTPS plugin, or the permalink itself.
464 *
465 * @since 2.5.0
466 * @return bool
467 */
468 function wc_checkout_is_https() {
469 return wc_site_is_https() || 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) || class_exists( 'WordPressHTTPS' ) || strstr( wc_get_page_permalink( 'checkout' ), 'https:' );
470 }
471
472 /**
473 * Checks whether the content passed contains a specific short code.
474 *
475 * @param string $tag Shortcode tag to check.
476 * @return bool
477 */
478 function wc_post_content_has_shortcode( $tag = '' ) {
479 global $post;
480
481 return is_singular() && is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, $tag );
482 }
483
484 /**
485 * Check if reviews are enabled.
486 *
487 * @since 3.6.0
488 * @return bool
489 */
490 function wc_reviews_enabled() {
491 return 'yes' === get_option( 'woocommerce_enable_reviews' );
492 }
493
494 /**
495 * Check if reviews ratings are enabled.
496 *
497 * @since 3.6.0
498 * @return bool
499 */
500 function wc_review_ratings_enabled() {
501 return wc_reviews_enabled() && 'yes' === get_option( 'woocommerce_enable_review_rating' );
502 }
503
504 /**
505 * Check if review ratings are required.
506 *
507 * @since 3.6.0
508 * @return bool
509 */
510 function wc_review_ratings_required() {
511 return 'yes' === get_option( 'woocommerce_review_rating_required' );
512 }
513
514 /**
515 * Check if a CSV file is valid.
516 *
517 * @since 3.6.5
518 * @param string $file File name.
519 * @param bool $check_path If should check for the path.
520 * @return bool
521 */
522 function wc_is_file_valid_csv( $file, $check_path = true ) {
523 /**
524 * Filter check for CSV file path.
525 *
526 * @since 3.6.4
527 * @param bool $check_import_file_path If requires file path check. Defaults to true.
528 * @param string $file Path of the file to be checked.
529 */
530 $check_import_file_path = apply_filters( 'woocommerce_csv_importer_check_import_file_path', true, $file );
531
532 if ( $check_path && $check_import_file_path && false !== stripos( $file, 'file://' ) ) {
533 return false;
534 }
535
536 /**
537 * Filter CSV valid file types.
538 *
539 * @since 3.6.5
540 * @param array $valid_filetypes List of valid file types.
541 */
542 $valid_filetypes = apply_filters(
543 'woocommerce_csv_import_valid_filetypes',
544 array(
545 'csv' => 'text/csv',
546 'txt' => 'text/plain',
547 )
548 );
549
550 $filetype = wp_check_filetype( $file, $valid_filetypes );
551
552 if ( in_array( $filetype['type'], $valid_filetypes, true ) ) {
553 return true;
554 }
555
556 return false;
557 }
558
559 /**
560 * Check if the current theme is a block theme.
561 *
562 * @since 6.0.0
563 * @deprecated 9.9.0 Use wp_is_block_theme() instead.
564 * @return bool
565 */
566 function wc_current_theme_is_fse_theme() {
567 wc_deprecated_function( __FUNCTION__, '9.9.0', 'wp_is_block_theme' );
568 return wp_is_block_theme();
569 }
570
571 /**
572 * Check if the current theme has WooCommerce support or is a FSE theme.
573 *
574 * @since 6.0.0
575 * @return bool
576 */
577 function wc_current_theme_supports_woocommerce_or_fse() {
578 return (bool) current_theme_supports( 'woocommerce' ) || wp_is_block_theme();
579 }
580
581 /**
582 * Given an element name, returns a class name.
583 *
584 * If the WP-related function is not defined or current theme is not a FSE theme, return empty string.
585 *
586 * @param string $element The name of the element.
587 *
588 * @since 7.0.1
589 * @return string
590 */
591 function wc_wp_theme_get_element_class_name( $element ) {
592 if ( wp_is_block_theme() && function_exists( 'wp_theme_get_element_class_name' ) ) {
593 return wp_theme_get_element_class_name( $element );
594 }
595
596 return '';
597 }
598
599 /**
600 * Given an element name, returns true or false depending on whether the
601 * current theme has styles for that element defined in theme.json.
602 *
603 * If the theme is not a block theme or the WP-related function is not defined,
604 * return false.
605 *
606 * @param string $element The name of the element.
607 *
608 * @since 7.4.0
609 * @return bool
610 */
611 function wc_block_theme_has_styles_for_element( $element ) {
612 if (
613 ! wp_is_block_theme() ||
614 wc_wp_theme_get_element_class_name( $element ) === ''
615 ) {
616 return false;
617 }
618
619 if ( function_exists( 'wp_get_global_styles' ) ) {
620 $global_styles = wp_get_global_styles();
621 if (
622 array_key_exists( 'elements', $global_styles ) &&
623 array_key_exists( $element, $global_styles['elements'] )
624 ) {
625 return is_array( $global_styles['elements'][ $element ] );
626 }
627 }
628
629 return false;
630 }
631