gpt4 book ai didi

php - WooCommerce 如何检查 functions.php 中的页面是否为 is_shop()?

转载 作者:可可西里 更新时间:2023-10-31 22:47:49 27 4
gpt4 key购买 nike

在 WooCommerce 中,我的类别列表页面和产品列表页面是从 archieve-product.php 呈现的(默认情况下)。如何检查functions.php 中的页面是否为is_shop()?因为 is_shop 函数在 functions.php 中不起作用。我只是想从类别列表中删除我的侧边栏页面,而不是从产品列表页面中删除。

最佳答案

当放置在钩子(Hook)中时,is_shop 将在 functions.php 中工作

add_action( 'template_redirect', 'custom_template_redirect' );

function custom_template_redirect() {

if( is_shop() ) :

// code logic here

endif;
}

这是所有 WooCommerce conditionals 的列表

关于php - WooCommerce 如何检查 functions.php 中的页面是否为 is_shop()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37350704/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com