Created
December 11, 2017 21:13
-
-
Save amiut/b12bbe256bf0914eca976f03a7352d1c to your computer and use it in GitHub Desktop.
Check if is woocommerce page or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Is woocommerce page | |
* | |
* @param string $page ( 'cart' | 'checkout' | 'account' | 'endpoint' ) | |
* @param string $endpoint If $page == 'endpoint' and you want to check for specific endpoint | |
* @return boolean | |
*/ | |
if( ! function_exists('is_woocommerce_page') ){ | |
function is_woocommerce_page( $page = '', $endpoint = '' ){ | |
if( ! $page ){ | |
return ( is_cart() || is_checkout() || is_account_page() || is_wc_endpoint_url() ); | |
} | |
switch ( $page ) { | |
case 'cart': | |
return is_cart(); | |
break; | |
case 'checkout': | |
return is_checkout(); | |
break; | |
case 'account': | |
return is_account_page(); | |
break; | |
case 'endpoint': | |
if( $endpoint ) { | |
return is_wc_endpoint_url( $endpoint ); | |
} | |
return is_wc_endpoint_url(); | |
break; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check if user is on one of woocommerce pages ( cart, checkout, my-account, ... )