dongyu9263 2019-04-24 16:26
浏览 81
已采纳

用于woocommerce filter_的add_rewrite_rule无效

I am trying to get the product list with some category and attribute. Dirrect link working well but custom_rewrite_rules not working as expected. Yes, I reload permalinks in admin panel. Please help to find solution. Woocommerce products list.

If I open index.php?product_cat=oil&filter_flavor=mint filter for category and product attribute will work as expected but when i will try localhost/shop/oil/mint i get products filtered by category only but missed filter_flavor

function custom_rewrite_rules() {
    add_rewrite_rule('^shop/([^/]*)/([^/]*)/?', 'index.php?product_cat=$matches[1]&filter_flavor=mint', 'top');
}
add_action('init', 'custom_rewrite_rules', 10, 0);
  • 写回答

1条回答 默认 最新

  • dpjo15650 2019-04-26 18:23
    关注

    Solution for this task is pretty simple. You can turn on "Enable Archives?" checkbox and save for some attribute in "Products->Attributes" from wp admin panel. Then you can get it by link index.php?product_cat=$matches[1]&pa_flavor=mint now rewrite rules from my question will work with this fixed url.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建