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