• Resolved NicolaCirotto

    (@nicolacirotto)


    Hi,
    I can’t find this answer. In wordpress if you open url with parameter mysite.com/?cat=1 automaticaly wordpress open the archive page of category 1 of posts like mysite.com/category/name-of-category/.
    In Woocommerce I can’t find how I can open the archive page with parameter in url like ?cat=22
    I need this because I want to use buttons to link to category product archive page and if one day I change the name of the category the link not broken.

    For example I have 2 categories for products: CategoryA and CategoryB
    In home page I have 2 buttons: “Show CategoryA” and “Show CategoryB”.
    I set href to buttons like: mysite.com/product-category/categorya/
    but if I change the slug of CategoryA my button will not work.

    I’m a developer and I created my solution but I want to ask you if exist the possibility to pass parameter cat id to url to open archive page of product category.

    This is my solution passing parameter ?product_cat=22
    example: mysite.com/?product_cat=22

    add_action( 'wp_loaded', 'my_muplugins_loaded', 10, 0 );
    function my_muplugins_loaded()
    {
    	if( isset($_GET['product_cat']) )
    	{
    		$term = get_term_by('term_taxonomy_id', (int)$_GET['product_cat']);
    		if( $term )
    		{
    			$link = get_term_link($term);
    			wp_redirect($link, 301);
    			exit;
    		}
    	}
    }
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Damianne P (a11n)

    (@drwpcom)

    Hi @nicolacirotto. You’re right that there is no built-in option to link to a product page using the category id, so this solution would need to be customized as you’ve done.

    MayKato

    (@maykato)

    Hi @nicolacirotto

    We’ve not heard back from you in a while, so I’m marking this thread as resolved. If you have further questions, please feel free to open a new topic.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Open category archive page by url parameter’ is closed to new replies.