我需要为一个特定的woocommerce类别设置一个不同的页面。我已经在管理面板中创建了该页面。当任何用户点击该类别时,我需要打开另一个页面。
所有其他类别将在点击时显示产品。我需要为一些特定的类别设置不同的页面。我知道我们可以创建具有分类法名称的模板,但我不需要将其创建为模板。我要打电话给管理员。
我怎样才能做到这一点?
如果我理解正确的话,您希望将产品类别重定向到WordPress 页面,那么您可以使用template_redirect
钩子。
function so_38101215_template_redirect(){
if( function_exists( 'is_product_category' ) && is_product_category( 'redirect_this_category' ) ){
$redirect_page_id = 99; // adjust to ID of page you are redirecting to
wp_redirect( get_permalink( $redirect_page_id ) );
exit();
}
}
add_action( 'template_redirect', 'so_38101215_template_redirect' );
template_redirect
在查询完全设置后被触发,因此您将能够使用标准条件逻辑来确定何时要运行重定向。
使用taxonomy-$taxonomy.php
作为模板,其中$taxonomy
为product_cat
。如果对于一个特定的类别,你需要不同的结构,那么使用taxonomy-$taxonomy-$term.php
。$term
是您的特定产品类别。
并确保您复制WooCommerce类别模板内容要复制到这里,然后根据需要进行更改。
顺便问一下,你说的'i need to call admin page'是什么意思?从这些模板中,您需要一些管理权限吗?