WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
BUG when creating Attributes with Scandinavian letters (1 post)

  1. Jonas Lundman
    Member
    Posted 9 months ago #

    Solution is provided in this message of this possible Bug. Also posted at github

    Some wierd stuff happend when saving new Attributes and tracked it down as follow:

    When creating new Attribute with a non english letter as the first char like : Önskas ångervecka

    No slug is created.

    It should return : onskas-angervecka

    The problem.

    Attribute names seems are created outside WP and uses :

    woocommerce_sanitize_taxonomy_name()

    found in : woocommerce-admin-attributes.php and it seems to return an empty string when string starts with "Ö". No Hooks or filters are provided to pre-filter this.

    Solution
    In woocommerce-admin-attributes.php Line 51 I wrapped the string to be filtered with:

    sanitize_title_with_dashes($_POST['attribute_name'], '', 'save')

    And Line 59:

    sanitize_title($attribute_label, '', 'save')

    The complete lines are provided at the end of this message.

    About my fix
    sanitize_title() is a WP cleanup for urls, and actually not a pretty title thing. Check out the codex. Maybe there is a better filter to use.

    The Attribute label is not passing WPs pre_insert_term filter, like cats and tags (And attribute values (!)) and if I understand right are Woo attribute names "Virtual" taxonomies. So a FILTER HOOK of names/labels would be nice!

    I created one myself (when crashing the core file anyway) to clean the Labels like I do with Category names in my theme.

    function ua_woocommerce_sanitize_taxonomy_label( $taxonomy )

    However, Here is the fix (ends with // QQ) in context:

    // Grab the submitted data
    		$attribute_label   = ( isset( $_POST['attribute_label'] ) )   ? (string) stripslashes( $_POST['attribute_label'] ) : '';
    		$attribute_name    = ( isset( $_POST['attribute_name'] ) )    ? woocommerce_sanitize_taxonomy_name( stripslashes( (string) sanitize_title_with_dashes($_POST['attribute_name'], '', 'save') ) ) : ''; // QQ
    		$attribute_type    = ( isset( $_POST['attribute_type'] ) )    ? (string) stripslashes( $_POST['attribute_type'] ) : '';
    		$attribute_orderby = ( isset( $_POST['attribute_orderby'] ) ) ? (string) stripslashes( $_POST['attribute_orderby'] ) : '';
    
    		// Auto-generate the label or slug if only one of both was provided
    		if ( ! $attribute_label ) {
    			$attribute_label = ucwords( $attribute_name );
    		} elseif ( ! $attribute_name ) {
    			$attribute_name = woocommerce_sanitize_taxonomy_name( stripslashes( sanitize_title($attribute_label, '', 'save') ) ); // QQ
    		}

    / Swedish developer

    http://wordpress.org/plugins/woocommerce/

Reply

You must log in to post.

About this Plugin

About this Topic

  • RSS feed for this topic
  • Started 9 months ago by Jonas Lundman
  • This topic is not a support question
  • WordPress version: 3.6.1