Created
May 23, 2014 13:35
-
-
Save mircobabini/56c71e616167d5fca4c5 to your computer and use it in GitHub Desktop.
Product Categories to Product Types (WPML Support)
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 | |
/** | |
* put into: | |
* woocommerce/archive-product.php | |
* | |
* foreach product category (slug) must exists a product type with the same slug ending in '-type' | |
* example: | |
* product category: shoes, product type: shoes-type ) | |
* | |
* License: GPLv2 | |
* Author: Mirco Babini <mirkolofio@gmail.com> | |
*/ | |
if( @$_GET['filter_product-type'] == null ){ | |
$R = explode( '/', $_SERVER['REQUEST_URI'] ); | |
array_shift( $R ); | |
array_pop( $R ); | |
$taxonomy = reset( $R ); | |
$value = end( $R ); | |
$term = get_term_by( 'slug', $value, 'product_cat' ); | |
if( $term ){ | |
$term_to = get_term_by( 'slug', $value.'-type', 'pa_product-type' ); | |
if( $term_to ){ | |
$shop_id = woocommerce_get_page_id( 'shop' ); | |
if( function_exists( 'icl_object_id' ) ){ | |
$shop_id = icl_object_id( $shop_id, 'page', true, ICL_LANGUAGE_CODE ); | |
} | |
$permalink = get_permalink( $shop_id ); | |
wp_redirect( $permalink . '/?filter_product-type=' . $term_to->term_id, 301 ); | |
exit; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment