Last active
February 5, 2019 09:36
-
-
Save chrono-meter/2194323f25b003e863076e264a2f4d7e to your computer and use it in GitHub Desktop.
FIX: WooCommerce generates non appropriate rewrite slug for product attributes with non latin language slug.
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 | |
/** | |
* @wordpress-plugin | |
* Plugin Name: FIX: WooCommerce generates non appropriate rewrite slug for product attributes with CJK language slug. | |
* Depends: WooCommerce | |
* Plugin URI: | |
* Description: | |
* Version: 1.0.0 | |
* Author: chrono-meter@gmx.net | |
* Author URI: mailto:chrono-meter@gmx.net | |
* License: GPL-2.0+ | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt | |
* | |
* @see WC_Post_Types::register_taxonomies | |
* @link https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-post-types.php | |
*/ | |
defined( 'ABSPATH' ) or exit; | |
add_action( 'init', function() { | |
if ( !defined( 'WC_PLUGIN_FILE' ) ) return; | |
$permalinks = wc_get_permalink_structure(); | |
$attribute_taxonomies = wc_get_attribute_taxonomies(); | |
if ( $attribute_taxonomies ) { | |
foreach ( $attribute_taxonomies as $tax ) { | |
$name = wc_attribute_taxonomy_name( $tax->attribute_name ); | |
add_filter( "woocommerce_taxonomy_args_{$name}", function($taxonomy_data) use($permalinks, $tax) { | |
if ( !empty( $taxonomy_data['rewrite'] ) ) { | |
$taxonomy_data['rewrite']['slug'] = trailingslashit( $permalinks['attribute_rewrite_slug'] ) . rawurldecode( sanitize_title( $tax->attribute_name ) ); | |
} | |
return $taxonomy_data; | |
} ); | |
} | |
} | |
}, 0 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment