Introduce function to check shortcode tag
This commit is contained in:
parent
4c29b7607f
commit
4f7858739d
|
@ -86,7 +86,7 @@ if ( ! function_exists( 'is_cart' ) ) {
|
|||
* @return bool
|
||||
*/
|
||||
function is_cart() {
|
||||
return is_page( wc_get_page_id( 'cart' ) ) || defined( 'WOOCOMMERCE_CART' ) || ( ! empty( $post ) && strstr( $post->post_content, '[woocommerce_cart' ) );
|
||||
return is_page( wc_get_page_id( 'cart' ) ) || defined( 'WOOCOMMERCE_CART' ) || is_wc_shortcode_tag( 'woocommerce_cart' );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,8 +97,7 @@ if ( ! function_exists( 'is_checkout' ) ) {
|
|||
* @return bool
|
||||
*/
|
||||
function is_checkout() {
|
||||
global $post;
|
||||
return is_page( wc_get_page_id( 'checkout' ) ) || ( ! empty( $post ) && strstr( $post->post_content, '[woocommerce_checkout' ) ) || apply_filters( 'woocommerce_is_checkout', false );
|
||||
return is_page( wc_get_page_id( 'checkout' ) ) || is_wc_shortcode_tag( 'woocommerce_checkout' ) || apply_filters( 'woocommerce_is_checkout', false );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,6 +114,20 @@ if ( ! function_exists( 'is_checkout_pay_page' ) ) {
|
|||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'is_wc_shortcode_tag' ) ) {
|
||||
|
||||
/**
|
||||
* is_wc_shortcode_tag - Returns true when the shortcode tag is found.
|
||||
* @param string $tag Shortcode tag to check.
|
||||
* @return bool
|
||||
*/
|
||||
function is_wc_shortcode_tag( $tag = '' ) {
|
||||
global $post;
|
||||
|
||||
return is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, $tag );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'is_wc_endpoint_url' ) ) {
|
||||
|
||||
/**
|
||||
|
@ -154,7 +167,7 @@ if ( ! function_exists( 'is_account_page' ) ) {
|
|||
* @return bool
|
||||
*/
|
||||
function is_account_page() {
|
||||
return is_page( wc_get_page_id( 'myaccount' ) ) || ( ! empty( $post ) && strstr( $post->post_content, '[woocommerce_my_account' ) ) || apply_filters( 'woocommerce_is_account_page', false );
|
||||
return is_page( wc_get_page_id( 'myaccount' ) ) || is_wc_shortcode_tag( 'woocommerce_my_account' ) || apply_filters( 'woocommerce_is_account_page', false );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -352,7 +365,6 @@ function wc_is_webhook_valid_topic( $topic ) {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simple check for validating a URL, it must start with http:// or https://.
|
||||
* and pass FILTER_VALIDATE_URL validation.
|
||||
|
|
Loading…
Reference in New Issue