Site icon Hip-Hop Website Design and Development

Pass Values in URL on WooCommerce Product Page

I currently pass values to a product page dynamically with $_GET params in url. However I’d like to switch to cleaner URLs.

Current product URL: /event/play/?eid=1765&wt=ou

I would like to change to: /event/play/1765/ou

Current attempt:

function rewrite_ww_product_pages() {
    add_rewrite_rule( '^event/play/([^/]*)/([^/]*)/?',
    'index.php?post_type=product&category_name=event&pagename=play&eid=$matches[1]&wt=$matches[2]', 'top' );
}
add_action( 'init', 'rewrite_ww_product_pages' );

function ww_custom_rewrite_tag() {
    add_rewrite_tag('%eid%', '([^&]+)');
    add_rewrite_tag('%wt%', '([^&]+)');
}
add_action('init', 'ww_custom_rewrite_tag', 10, 0);


// In Product Template I tried getting:
global $wp_query;
$eid = $wp_query->query_vars['eid'];
$wt = $wp_query->query_vars['wt'];
// and
$eid = get_query_var('eid');
$wt = get_query_var('wt');

The URL loads, but strips the params from URL.

/event/play/1765/ou redirects to /event/play/

I tested with a Rewrite Analyzer plugin and it looks to match, but maybe the second match is issue?