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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 5 years ago admin 5 years ago cli 5 years ago customizer 5 years ago data-stores 4 years ago emails 5 years ago export 5 years ago gateways 5 years ago import 5 years ago integrations 5 years ago interfaces 5 years ago legacy 5 years ago libraries 6 years ago log-handlers 5 years ago payment-tokens 5 years ago queue 5 years ago rest-api 5 years ago shipping 5 years ago shortcodes 5 years ago theme-support 5 years ago tracks 5 years ago traits 5 years ago walkers 5 years ago wccom-site 5 years ago widgets 5 years ago class-wc-ajax.php 5 years ago class-wc-api.php 5 years ago class-wc-auth.php 5 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 5 years ago class-wc-cart-fees.php 5 years ago class-wc-cart-session.php 5 years ago class-wc-cart-totals.php 5 years ago class-wc-cart.php 5 years ago class-wc-checkout.php 5 years ago class-wc-cli.php 8 years ago class-wc-comments.php 5 years ago class-wc-countries.php 5 years ago class-wc-coupon.php 5 years ago class-wc-customer-download-log.php 5 years ago class-wc-customer-download.php 5 years ago class-wc-customer.php 5 years ago class-wc-data-exception.php 8 years ago class-wc-data-store.php 6 years ago class-wc-datetime.php 5 years ago class-wc-deprecated-action-hooks.php 8 years ago class-wc-deprecated-filter-hooks.php 7 years ago class-wc-discounts.php 5 years ago class-wc-download-handler.php 5 years ago class-wc-emails.php 5 years ago class-wc-embed.php 5 years ago class-wc-form-handler.php 5 years ago class-wc-frontend-scripts.php 5 years ago class-wc-geo-ip.php 5 years ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 5 years ago class-wc-https.php 5 years ago class-wc-install.php 5 years ago class-wc-integrations.php 5 years ago class-wc-log-levels.php 5 years ago class-wc-logger.php 5 years ago class-wc-meta-data.php 7 years ago class-wc-order-factory.php 5 years ago class-wc-order-item-coupon.php 5 years ago class-wc-order-item-fee.php 5 years ago class-wc-order-item-meta.php 5 years ago class-wc-order-item-product.php 5 years ago class-wc-order-item-shipping.php 5 years ago class-wc-order-item-tax.php 5 years ago class-wc-order-item.php 5 years ago class-wc-order-query.php 5 years ago class-wc-order-refund.php 5 years ago class-wc-order.php 5 years ago class-wc-payment-gateways.php 5 years ago class-wc-payment-tokens.php 5 years ago class-wc-post-data.php 5 years ago class-wc-post-types.php 5 years ago class-wc-privacy-background-process.php 5 years ago class-wc-privacy-erasers.php 6 years ago class-wc-privacy-exporters.php 6 years ago class-wc-privacy.php 5 years ago class-wc-product-attribute.php 5 years ago class-wc-product-download.php 5 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 5 years ago class-wc-product-variable.php 5 years ago class-wc-product-variation.php 5 years ago class-wc-query.php 5 years ago class-wc-rate-limiter.php 5 years ago class-wc-regenerate-images-request.php 5 years ago class-wc-regenerate-images.php 5 years ago class-wc-register-wp-admin-settings.php 5 years ago class-wc-rest-authentication.php 5 years ago class-wc-rest-exception.php 5 years ago class-wc-session-handler.php 5 years ago class-wc-shipping-rate.php 5 years ago class-wc-shipping-zone.php 5 years ago class-wc-shipping-zones.php 5 years ago class-wc-shipping.php 5 years ago class-wc-shortcodes.php 5 years ago class-wc-structured-data.php 5 years ago class-wc-tax.php 5 years ago class-wc-template-loader.php 5 years ago class-wc-tracker.php 5 years ago class-wc-validation.php 5 years ago class-wc-webhook.php 5 years ago class-woocommerce.php 4 years ago wc-account-functions.php 5 years ago wc-attribute-functions.php 5 years ago wc-cart-functions.php 5 years ago wc-conditional-functions.php 5 years ago wc-core-functions.php 5 years ago wc-coupon-functions.php 5 years ago wc-deprecated-functions.php 5 years ago wc-formatting-functions.php 5 years ago wc-notice-functions.php 5 years ago wc-order-functions.php 5 years ago wc-order-item-functions.php 5 years ago wc-page-functions.php 5 years ago wc-product-functions.php 5 years ago wc-rest-functions.php 5 years ago wc-stock-functions.php 5 years ago wc-template-functions.php 5 years ago wc-template-hooks.php 5 years ago wc-term-functions.php 5 years ago wc-update-functions.php 5 years ago wc-user-functions.php 5 years ago wc-webhook-functions.php 5 years ago wc-widget-functions.php 5 years ago
wc-conditional-functions.php
497 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 * @return bool
265 */
266 function is_ajax() {
267 return function_exists( 'wp_doing_ajax' ) ? wp_doing_ajax() : Constants::is_defined( 'DOING_AJAX' );
268 }
269 }
270
271 if ( ! function_exists( 'is_store_notice_showing' ) ) {
272
273 /**
274 * Is_store_notice_showing - Returns true when store notice is active.
275 *
276 * @return bool
277 */
278 function is_store_notice_showing() {
279 return 'no' !== get_option( 'woocommerce_demo_store', 'no' );
280 }
281 }
282
283 if ( ! function_exists( 'is_filtered' ) ) {
284
285 /**
286 * Is_filtered - Returns true when filtering products using layered nav or price sliders.
287 *
288 * @return bool
289 */
290 function is_filtered() {
291 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.
292 }
293 }
294
295 if ( ! function_exists( 'taxonomy_is_product_attribute' ) ) {
296
297 /**
298 * Returns true when the passed taxonomy name is a product attribute.
299 *
300 * @uses $wc_product_attributes global which stores taxonomy names upon registration
301 * @param string $name of the attribute.
302 * @return bool
303 */
304 function taxonomy_is_product_attribute( $name ) {
305 global $wc_product_attributes;
306
307 return taxonomy_exists( $name ) && array_key_exists( $name, (array) $wc_product_attributes );
308 }
309 }
310
311 if ( ! function_exists( 'meta_is_product_attribute' ) ) {
312
313 /**
314 * Returns true when the passed meta name is a product attribute.
315 *
316 * @param string $name of the attribute.
317 * @param string $value of the attribute.
318 * @param int $product_id to check for attribute.
319 * @return bool
320 */
321 function meta_is_product_attribute( $name, $value, $product_id ) {
322 $product = wc_get_product( $product_id );
323
324 if ( $product && method_exists( $product, 'get_variation_attributes' ) ) {
325 $variation_attributes = $product->get_variation_attributes();
326 $attributes = $product->get_attributes();
327 return ( in_array( $name, array_keys( $attributes ), true ) && in_array( $value, $variation_attributes[ $attributes[ $name ]['name'] ], true ) );
328 } else {
329 return false;
330 }
331 }
332 }
333
334 if ( ! function_exists( 'wc_tax_enabled' ) ) {
335
336 /**
337 * Are store-wide taxes enabled?
338 *
339 * @return bool
340 */
341 function wc_tax_enabled() {
342 return apply_filters( 'wc_tax_enabled', get_option( 'woocommerce_calc_taxes' ) === 'yes' );
343 }
344 }
345
346 if ( ! function_exists( 'wc_shipping_enabled' ) ) {
347
348 /**
349 * Is shipping enabled?
350 *
351 * @return bool
352 */
353 function wc_shipping_enabled() {
354 return apply_filters( 'wc_shipping_enabled', get_option( 'woocommerce_ship_to_countries' ) !== 'disabled' );
355 }
356 }
357
358 if ( ! function_exists( 'wc_prices_include_tax' ) ) {
359
360 /**
361 * Are prices inclusive of tax?
362 *
363 * @return bool
364 */
365 function wc_prices_include_tax() {
366 return wc_tax_enabled() && apply_filters( 'woocommerce_prices_include_tax', get_option( 'woocommerce_prices_include_tax' ) === 'yes' );
367 }
368 }
369
370 /**
371 * Simple check for validating a URL, it must start with http:// or https://.
372 * and pass FILTER_VALIDATE_URL validation.
373 *
374 * @param string $url to check.
375 * @return bool
376 */
377 function wc_is_valid_url( $url ) {
378
379 // Must start with http:// or https://.
380 if ( 0 !== strpos( $url, 'http://' ) && 0 !== strpos( $url, 'https://' ) ) {
381 return false;
382 }
383
384 // Must pass validation.
385 if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) {
386 return false;
387 }
388
389 return true;
390 }
391
392 /**
393 * Check if the home URL is https. If it is, we don't need to do things such as 'force ssl'.
394 *
395 * @since 2.4.13
396 * @return bool
397 */
398 function wc_site_is_https() {
399 return false !== strstr( get_option( 'home' ), 'https:' );
400 }
401
402 /**
403 * Check if the checkout is configured for https. Look at options, WP HTTPS plugin, or the permalink itself.
404 *
405 * @since 2.5.0
406 * @return bool
407 */
408 function wc_checkout_is_https() {
409 return wc_site_is_https() || 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) || class_exists( 'WordPressHTTPS' ) || strstr( wc_get_page_permalink( 'checkout' ), 'https:' );
410 }
411
412 /**
413 * Checks whether the content passed contains a specific short code.
414 *
415 * @param string $tag Shortcode tag to check.
416 * @return bool
417 */
418 function wc_post_content_has_shortcode( $tag = '' ) {
419 global $post;
420
421 return is_singular() && is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, $tag );
422 }
423
424 /**
425 * Check if reviews are enabled.
426 *
427 * @since 3.6.0
428 * @return bool
429 */
430 function wc_reviews_enabled() {
431 return 'yes' === get_option( 'woocommerce_enable_reviews' );
432 }
433
434 /**
435 * Check if reviews ratings are enabled.
436 *
437 * @since 3.6.0
438 * @return bool
439 */
440 function wc_review_ratings_enabled() {
441 return wc_reviews_enabled() && 'yes' === get_option( 'woocommerce_enable_review_rating' );
442 }
443
444 /**
445 * Check if review ratings are required.
446 *
447 * @since 3.6.0
448 * @return bool
449 */
450 function wc_review_ratings_required() {
451 return 'yes' === get_option( 'woocommerce_review_rating_required' );
452 }
453
454 /**
455 * Check if a CSV file is valid.
456 *
457 * @since 3.6.5
458 * @param string $file File name.
459 * @param bool $check_path If should check for the path.
460 * @return bool
461 */
462 function wc_is_file_valid_csv( $file, $check_path = true ) {
463 /**
464 * Filter check for CSV file path.
465 *
466 * @since 3.6.4
467 * @param bool $check_import_file_path If requires file path check. Defaults to true.
468 */
469 $check_import_file_path = apply_filters( 'woocommerce_csv_importer_check_import_file_path', true );
470
471 if ( $check_path && $check_import_file_path && false !== stripos( $file, '://' ) ) {
472 return false;
473 }
474
475 /**
476 * Filter CSV valid file types.
477 *
478 * @since 3.6.5
479 * @param array $valid_filetypes List of valid file types.
480 */
481 $valid_filetypes = apply_filters(
482 'woocommerce_csv_import_valid_filetypes',
483 array(
484 'csv' => 'text/csv',
485 'txt' => 'text/plain',
486 )
487 );
488
489 $filetype = wp_check_filetype( $file, $valid_filetypes );
490
491 if ( in_array( $filetype['type'], $valid_filetypes, true ) ) {
492 return true;
493 }
494
495 return false;
496 }
497