[英]WooCommerce: Check if is shop page and not archive / category
I want to check if I'm on the WooCommerce shop page.我想检查我是否在 WooCommerce 商店页面上。
There is the conditional tag is_shop()<\/code> .
有条件标签
is_shop()<\/code> 。
But that's
true<\/code> even if I'm on an archive page.
但即使我在存档页面上也是
true<\/code> 。
The shop page returns also
true<\/code> if I check for
is_archive()<\/code> and\/or
is_post_type_archive()<\/code> .
如果我检查
is_archive()<\/code>和\/或
is_post_type_archive()<\/code> ,商店页面也会返回
true<\/code> 。
I tried to check for the page ID of the shop page (in my case 6) with
is_page('6')<\/code> .
我尝试使用
is_page('6')<\/code> 。
But
is_page()<\/code> always returns
false<\/code> on the shop page?!
但是
is_page()<\/code>在商店页面上总是返回
false<\/code> ?!
Is there any way to check if I'm on the shop page and no other page\/archive?有什么方法可以检查我是否在商店页面上而没有其他页面\/存档?
I do have some archives like a vendor archive from "WC Vendors Pro" which doesn't have any conditional tags.我确实有一些档案,例如来自“WC Vendors Pro”的供应商档案,它没有任何条件标签。 Therefore I need to know exactly if I'm on the shop page (with ID 6) or not.因此,我需要确切地知道我是否在商店页面(ID 6)上。
"
you can try this custom way also,您也可以尝试这种自定义方式,
function shop_page_url_condition(){
global $wp;
$paged = get_query_var( 'paged');
$shop_page_id = get_option( 'woocommerce_shop_page_id' );
if(empty($shop_page_id)){return;}
$shop_page_url = get_permalink($shop_page_id );
if (!empty($paged)) {
$shop_page_url = get_permalink($shop_page_id ).'page/'.$paged.'/';
}
$current_url = home_url(add_query_arg(array(), $wp->request.'/'));
if( $shop_page_url == $current_url) {
return true;
}else{
return false;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.