Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mircobabini/56c71e616167d5fca4c5 to your computer and use it in GitHub Desktop.
Save mircobabini/56c71e616167d5fca4c5 to your computer and use it in GitHub Desktop.
Product Categories to Product Types (WPML Support)
<?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