Ecommerce Shopify WordPress Discussion

How to redirect each WooCommerce product category to a different page

i want to redirect separately all categories to specific pages. Found this code, but this is only for one category to one page, i need to this fo 20 categories to 20 different pages. function custom_category_template_redirect() { if ( is_product_category() ) { $category = get_queried_object(); if ( $category->term_id == 29, ) { $redirect_page_id = 304; wp_redirect( get_permalink( $redirect_page_id ) ); exit(); } } } add_action( 'template_redirect', 'custom_category_template_redirect' ); Someone to help me to resolve this case.
It's easy… you need to set an array of product category term IDs (keys) => redirection page IDs (values) pairs, in your function, like: add_action( 'template_redirect', 'product_category_archives_custom_redirects' ); function product_category_archives_custom_redirects() { if ( is_product_category() ) { $term_id = (string) get_queried_object_id(); // Array of term IDs (keys) => page IDs (values) $data = array( '29' => '304', '31' => '305', '32' => '312', ); if ( array_key_exists( $term_id, $data ) ) { wp_redirect( get_permalink( intval($data[$term_id]) ) ); exit(); } } } Code goes in functions.php file of your child theme (or in a plugin). Tested and work.

February 13, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.