Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DrewAPicture/fe6af5e7d947aa7cb2d8286acf23d15b to your computer and use it in GitHub Desktop.
Save DrewAPicture/fe6af5e7d947aa7cb2d8286acf23d15b to your computer and use it in GitHub Desktop.
add_filter( 'rewrite_rules_array', function( $rules ) {
if ( ! function_exists( 'WC' ) || ! function_exists( 'affiliate_wp' ) ) {
return $rules;
}
if ( true === version_compare( WC()->version, '3.0.0', '>=' ) ) {
$permalinks = wc_get_permalink_structure();
} else {
$permalinks = get_option( 'woocommerce_permalinks' );
}
$category_base = empty( $permalinks['category_base'] ) ? _x( 'product-category', 'slug', 'woocommerce' ) : $permalinks['category_base'];
$ref = affiliate_wp()->tracking->get_referral_var();
$category_rules = array(
$category_base . '/(.+?)/' . $ref . '(/(.*))?/?$' => 'index.php?product_cat=$matches[1]&' . $ref . '=$matches[3]'
);
$rules = array_merge( $category_rules, $rules );
return $rules;
}, 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment