woocommerce offtopic - Subcategories not working when using shared base with custom taxonomy

I have a custom URL structure for my WooCommerce setup.Essentially, I have a custom taxonomy (pwb-brand) with the same

I have a custom URL structure for my WooCommerce setup. Essentially, I have a custom taxonomy (pwb-brand) with the same base as the default (product_cat) taxonomy. To make pagination for both product categories and brands work, I used a piece of code to help WordPress distinguish brands from product categories. This works, but creates a situation where nested categories pages return a 404. To illustrate, site/catalog/brand and site/catalog/category work fine, pagination included, but site/catalog/category/subcategory returns a 404. Here's the code:

// Fix pagination
function wc_categories_might_be_brands( $query ) {
  if( ! is_admin() && isset( $query->query_vars['product_cat'] ) ){
    $term = get_term_by( 'slug', $query->query_vars['product_cat'], 'product_cat' );
    if( false == $term ){
      $query->query_vars['pwb-brand'] = $query->query_vars['product_cat'];
      unset( $query->query_vars['product_cat'] );
    }
  }
}
add_action( 'parse_request', 'wc_categories_might_be_brands' );

How do I modify it to account for subcategories or skip checking subcategory queries altogether (because brands have no nested terms)?
I'm a noob with PHP. Please explain like I'm 5.
Thank you!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744636353a4585166.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信