Skip to content

Instantly share code, notes, and snippets.

@ssbalakumar
Created May 5, 2018 10:53
Show Gist options
  • Save ssbalakumar/42f4e82af40dc130bce027c70b94fe06 to your computer and use it in GitHub Desktop.
Save ssbalakumar/42f4e82af40dc130bce027c70b94fe06 to your computer and use it in GitHub Desktop.
Use Latest wordpress & woocommerce with Perfect SEO URL Plugin 2.6.7 The product-category not removed from 3.3.x woocommerce
Use Latest wordpress & woocommerce with Perfect SEO URL Plugin 2.6.7
The product-category not removed from 3.3.x woocommerce
Tricks here Credit - https://timersys.com/remove-product-category-slug-woocommerce/
------------
add_filter('request', function( $vars ) {
global $wpdb;
if( ! empty( $vars['pagename'] ) || ! empty( $vars['category_name'] ) || ! empty( $vars['name'] ) || ! empty( $vars['attachment'] ) ) {
$slug = ! empty( $vars['pagename'] ) ? $vars['pagename'] : ( ! empty( $vars['name'] ) ? $vars['name'] : ( !empty( $vars['category_name'] ) ? $vars['category_name'] : $vars['attachment'] ) );
$exists = $wpdb->get_var( $wpdb->prepare( "SELECT t.term_id FROM $wpdb->terms t LEFT JOIN $wpdb->term_taxonomy tt ON tt.term_id = t.term_id WHERE tt.taxonomy = 'product_cat' AND t.slug = %s" ,array( $slug )));
if( $exists ){
$old_vars = $vars;
$vars = array('product_cat' => $slug );
if ( !empty( $old_vars['paged'] ) || !empty( $old_vars['page'] ) )
$vars['paged'] = ! empty( $old_vars['paged'] ) ? $old_vars['paged'] : $old_vars['page'];
if ( !empty( $old_vars['orderby'] ) )
$vars['orderby'] = $old_vars['orderby'];
if ( !empty( $old_vars['order'] ) )
$vars['order'] = $old_vars['order'];
}
}
return $vars;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment