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