Skip to content

Instantly share code, notes, and snippets.

@dawnerd
Last active August 29, 2015 13:56
Show Gist options
  • Save dawnerd/8854841 to your computer and use it in GitHub Desktop.
Save dawnerd/8854841 to your computer and use it in GitHub Desktop.
Allows category and product to share a same base in woocommerce.
<?php
add_filter('request', function( $request ) {
$tax_qv = 'product_cat';
$cpt_name = 'product';
if(!empty( $request[$tax_qv])) {
$slug = basename($request[$tax_qv]);
// if this would generate a 404
if(!get_term_by('slug', $slug, $tax_qv)) {
// set the correct query vars
$request['name'] = $slug;
$request['post_type'] = $cpt_name;
unset($request[$tax_qv]);
}
}
return $request;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment