Skip to content

Instantly share code, notes, and snippets.

@chrono-meter
Last active February 5, 2019 09:36
Show Gist options
  • Save chrono-meter/2194323f25b003e863076e264a2f4d7e to your computer and use it in GitHub Desktop.
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.
<?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