Skip to content

Instantly share code, notes, and snippets.

@amiut
Created December 11, 2017 21:13
Show Gist options
  • Save amiut/b12bbe256bf0914eca976f03a7352d1c to your computer and use it in GitHub Desktop.
Save amiut/b12bbe256bf0914eca976f03a7352d1c to your computer and use it in GitHub Desktop.
Check if is woocommerce page or not
/**
* 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;
}
}
@amiut
Copy link
Author

amiut commented Dec 11, 2017

Check if user is on one of woocommerce pages ( cart, checkout, my-account, ... )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment