Custom URL for each product variation – rewrite rules


I would like to have a separate url for each of my product variations. For that I would need to create a rewrite rule, that will work on the product URLs

Ie, my product URL is

The product has two variations – size and color. I would like to be able to access the product on url like

This clearly has something to do with the add_rewrite_rule function. I don’t know how to build the url structure to be able to access the variations part of url

function custom_rewrite_basic() {
  add_rewrite_rule('^product/([0-9]+)/([0-9]+)?', 'index.php?page_id=$matches[1]&variations=$matches[2]', 'top');
add_action('init', 'custom_rewrite_basic');


, , user1049961 3 years 2020-03-30T16:51:57-05:00 0 Answers 88 views 0

Leave an answer