Last active
January 12, 2018 06:50
-
-
Save thesadoo/e61db88b94b5f134799c77eaa1794d59 to your computer and use it in GitHub Desktop.
Remove WooCommerce hierarchical product category URL rewrites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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