#StackBounty: #woocommerce #rewrite-rules #add-rewrite-rule Custom rewrite for product variation not working

Bounty: 50

I’m trying to rewrite the product variation url for a Phone Model attribute for example to this url:


This works when I open it in the browser directly. So the original url I’d like to be:


I tried with the code below, but it is not working.

function add_model_taxonomy_args($args) {
    $args['query_var'] = 'attribute_pa_model';
    return $args;
add_filter('woocommerce_taxonomy_args_pa_model', 'add_model_taxonomy_args' ); 

function custom_rewrite_rules() {
    add_rewrite_tag('%attribute_pa_model%', '([a-zA-Z0-9-]+)');
    add_rewrite_rule('^product/(.+?)/(.+?)/?$', 'index.php?product=$matches[1]&attribute_pa_model=$matches[2]', 'top');

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.