Last active
April 22, 2024 18:31
-
-
Save razorfrog/4125ffe0677579f5338d0641cf6ea939 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
// Change attribute rewrite rules | |
add_action('woocommerce_register_taxonomy', 'razorfrog_woo_register_taxonomy'); | |
function razorfrog_woo_register_taxonomy() { | |
global $razorfrog_woo_attribute_labels; | |
$razorfrog_woo_attributes_labels = array(); | |
if ( $attribute_taxonomies = wc_get_attribute_taxonomies() ) { | |
foreach ( $attribute_taxonomies as $tax ) { | |
if ( $name = wc_attribute_taxonomy_name( $tax->attribute_name ) ) { | |
$razorfrog_woo_attribute_labels[ $tax->attribute_label ] = $tax->attribute_name; | |
add_filter('woocommerce_taxonomy_args_'.$name, 'razorfrog_woo_taxonomy_args'); | |
} | |
} | |
} | |
} | |
function razorfrog_woo_taxonomy_args($taxonomy_data) { | |
global $razorfrog_woo_attribute_labels; | |
if (isset($taxonomy_data['rewrite']) && is_array($taxonomy_data['rewrite']) && empty($taxonomy_data['rewrite']['slug'])) { | |
$taxonomy_data['rewrite']['slug'] = $razorfrog_woo_attribute_labels[ $taxonomy_data['labels']['name'] ]; | |
} | |
return $taxonomy_data; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment