Skip to content

Instantly share code, notes, and snippets.

@thesadoo
Last active January 12, 2018 06:50
Show Gist options
  • Save thesadoo/e61db88b94b5f134799c77eaa1794d59 to your computer and use it in GitHub Desktop.
Save thesadoo/e61db88b94b5f134799c77eaa1794d59 to your computer and use it in GitHub Desktop.
Remove WooCommerce hierarchical product category URL rewrites
<?php
# the neat way using WooCommerce filter
function remove_wc_product_cat_hierarchy($args){
$args['rewrite']['hierarchical'] = false;
return $args;
}
add_filter('woocommerce_taxonomy_args_product_cat', 'remove_wc_product_cat_hierarchy');
# this is the wrong way cause it throws 404 and adds another override
function remove_wc_product_cat_hierarchy() {
$product_cat_args = get_taxonomy( 'product_cat' );
$product_cat_args->rewrite['hierarchical'] = false;
register_taxonomy( 'product-category', 'product', (array) $product_cat_args );
}
add_action( 'init', 'remove_wc_product_cat_hierarchy', 11 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment