产品子类别的 Woocommerce 重写规则 [英] Woocommerce rewrite rule for product sub category
本文介绍了产品子类别的 Woocommerce 重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在此处使用此代码:
add_filter('rewrite_rules_array', function( $rules )
{
$new_rules = array(
'products/([^/]*?)/page/([0-9]{1,})/?$' => 'index.php?product_cat=$matches[1]&paged=$matches[2]',
'products/([^/]*?)/?$' => 'index.php?product_cat=$matches[1]',
);
return $new_rules + $rules;
});
并拥有这些永久链接设置
And having these permalink settings
产品类别基础: 产品
产品固定链接 - 自定义基础: /products/%product_cat%
我得到以下信息:
/products/%category_name%/
(父产品类别页面工作正常)./products/%category_name%/%subcategory_name/
(子产品类别页面不起作用 - 获得 404)./products/%category_name%/%subcategory_name/%product_name
(单个产品工作正常).
/products/%category_name%/
(Parent Product Category Page works fine)./products/%category_name%/%subcategory_name/
(Child Product Category Page does not work - gets 404)./products/%category_name%/%subcategory_name/%product_name
(Single Products works fine).
有人对如何让子产品类别页面不抛出 404 错误有任何见解吗?
Anybody have any insight on how to get the Child Product Category pages to not throw the 404 error?
推荐答案
我解决了这些问题,我们应该对上面的代码做一些小改动.
I fixed these issue we should do some little changes in above code.
add_filter( 'rewrite_rules_array', function( $rules )
{
$new_rules = array(
'products/([^/]+?)/?$' => 'index.php?product_cat=$matches[1]',
'products(?:/.*)*?/(<!--some-indentword-->-[^/]+)/?$' => 'index.php?product_cat=$matches[1]',
);
return $new_rules + $rules;
} ,20,1);
它非常适合我.
这篇关于产品子类别的 Woocommerce 重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文