You can use the ‘template_include’ filter to specify a specific file be used as a template. It ought to be clear that you should only return your template file reference to the filter when the appropriate store values are in $_GET.
You also need code to actually query for the requested store data. I’m assuming you’ve done this on your template file. I only mention this in case you haven’t done so.
FWIW, “route” is a poor choice of terminology IMO for your question because “route” in WP is specifically for REST API routes. While your permalink, permastruct, request, URL, URI, or whatever it’s called as long as it’s not “route”, has a similar format to API routes, it doesn’t work in the API, so IMO it should not be called a “route”. If your intent was to make it an actual API route, you’re going about it the wrong way.
@bcworkz thanks for your reply. You are right. “route” is not a proper term for my question. I just want to define a custom URL structure for links in my plugins. When user clicks on the link, I want to display proper page. For example, in Woocommerce plugin file structure, different pages have been defined in templates directory, but I don’t know (I didn’t find the code) how does Woocommerce load the proper template page based on related request? I want to learn more about loading template files for different URLs in plugins.
Thanks
Core code determines the template to use in template-loader.php. The source code there is fairly clear, have a look. I imagine WooCommerce uses the “template_include” filter (at line 77) in a similar manner. For WooCommerce specific information, you could try to examine the source code, but admittedly it’s hard to follow. You could try asking in their dedicated support forum. The expert users and devs there are in a better place to answer WC specific questions.
You can see from the template-loader.php code that the template loaded depends on which query vars are set, determined by functions like is_front_page(). You might wonder how these query vars are determined from any particular request. That answer gets rather involved. For that, I refer you to the Query Overview.
@bcworkz Thanks for your explanation, I changed my code and I used template_include filter to load my template file, but it still redirects to home page. I don’t know why! I searched more for similar questions. All answers say using template_include filter can solve this problem. It seems this solution works for all but me!
Huh, that’s odd. AFAIK, everything goes through template loader. Add your callback function with a large priority argument to ensure it has the final say in template selection. Check the action is calling your added function by inserting an error_log() call. If no message is logged, some other code is redirecting before template loader. If a message is logged, verify your callback code is correctly deciding when to return your template and when to pass the default on through.