Last active
May 23, 2017 17:18
-
-
Save DrewAPicture/fe6af5e7d947aa7cb2d8286acf23d15b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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