Anonymous Anonymous - 11 months ago
685 0
PHP

old code

function woo_сс_query_vars($query_vars) {
    if( isset( $query_vars['category_name'] ) ) {
        $slug = $query_vars['category_name'];
    } else if( isset( $query_vars['product_cat'] ) ) {
        $slug = $query_vars['product_cat'];
    }
    if( isset( $slug ) ) {
        $slug_array = explode('/', $slug );
        $category = get_term_by('slug', $slug_array[0], 'product_cat', 'ARRAY_A');
        if( $category !== false ) {
            if( isset( $slug_array[1] ) ) {
                $query_vars['pa_brand'] = $slug_array[1];
            } else if( isset( $_GET['pa_brand'] ) ) {
                wp_redirect( str_replace( $slug_array[0], $slug_array[0] . '/' . $_GET['pa_brand'], remove_query_arg( 'pa_brand' ) ) );
                exit;
            }
            if( isset( $query_vars['category_name'] ) ) {
                $name = $slug_array[0];
                $query_vars['product_cat'] = $name;
                unset($query_vars['category_name']);
                $query_vars['product_cat'] = $name;
                unset($query_vars['category_name']);
            } else if( isset( $query_vars['product_cat'] ) ) {
                $query_vars['product_cat'] = $slug_array[0];
            }
        } else {
            $category = get_term_by('slug', $slug, 'category', 'ARRAY_A');
            if( isset( $query_vars['product_cat'] ) ) {
                $name = $query_vars['product_cat'];
                $query_vars['category_name'] = $name;
                unset($query_vars['product_cat']);
                $query_vars['category_name'] = $name;
                unset($query_vars['product_cat']);
            }
        }
    }
    return $query_vars;
}
add_action( 'request', 'woo_сс_query_vars' );

function woo_cc_insert_query_vars($vars) {
    array_push( $vars, 'pa_brand' );
    return $vars;
}
add_filter( 'query_vars', 'woo_cc_insert_query_vars' );

function woo_сс_term_link( $termlink, $term, $taxonomy ) {
    global $wp_rewrite;
    if( 'product_cat' == $taxonomy ) {
        $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
        $slug = $term->slug;
        $termlink = str_replace("%$taxonomy%", $slug, $termlink);
        $termlink = home_url( user_trailingslashit($termlink, 'category') );
        return $termlink;
    }
}
add_filter( 'term_link', 'woo_сс_term_link', 10, 3 );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download