Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Add rewrite Rules for WooCommerce product-category|product-tag + attribute taxonomy
- * ex: site.com/product-category/bacon/color/red ,etc
- */
- function mv_add_rewrite_rule(){
- global $woocommerce;
- /**
- * Slugs
- **/
- $shop_page_id = woocommerce_get_page_id('shop');
- $base_slug = ($shop_page_id > 0 && get_page( $shop_page_id )) ? get_page_uri( $shop_page_id ) : 'shop';
- $category_slug = (get_option('woocommerce_product_category_slug')) ? get_option('woocommerce_product_category_slug') : _x('product-category', 'slug', 'woocommerce');
- $tag_slug = (get_option('woocommerce_product_tag_slug')) ? get_option('woocommerce_product_tag_slug') : _x('product-tag', 'slug', 'woocommerce');
- $attribute_taxonomies = $woocommerce->attribute_taxonomies;
- if ( $attribute_taxonomies ) :
- foreach ($attribute_taxonomies as $tax) :
- $attribute = strtolower(sanitize_title($tax->attribute_name));
- $taxonomy = $woocommerce->attribute_taxonomy_name($attribute);
- if(get_option('woocommerce_prepend_shop_page_to_urls')=="yes"){
- add_rewrite_rule( $base_slug .'/'. $category_slug.'/(.+?)/'.$attribute.'/([^/]+)(/page/([0-9]+)?)?/?$',
- 'index.php?product_cat=$matches[1]&'.$taxonomy.'=$matches[2]&paged=$matches[4]',
- 'top' );
- add_rewrite_rule( $base_slug .'/'. $tag_slug.'/(.+?)/'.$attribute.'/([^/]+)(/page/([0-9]+)?)?/?$',
- 'index.php?product_tag=$matches[1]&'.$taxonomy.'=$matches[2]&paged=$matches[4]',
- 'top' );
- } else {
- add_rewrite_rule( $category_slug.'/(.+?)/'.$attribute.'/([^/]+)(/page/([0-9]+)?)?/?$',
- 'index.php?product_cat=$matches[1]&'.$taxonomy.'=$matches[2]&paged=$matches[4]',
- 'top' );
- add_rewrite_rule( $tag_slug.'/(.+?)/'.$attribute.'/([^/]+)(/page/([0-9]+)?)?/?$',
- 'index.php?product_tag=$matches[1]&'.$taxonomy.'=$matches[2]&paged=$matches[4]',
- 'top' );
- }
- endforeach;
- endif;
- }
- add_action('init','mv_add_rewrite_rule');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement