1

Google did not fix my problem so..

Anyone here know how to increase the character limit for woocommerce product attribute slug, default it has a limit of 28 characters (max 32 in database) i need max 40.(tried to increase to max 128).

I’m testing a local site where product information comes from imported xml files, sometimes certain attribute names are just longer than 28 characters..

Changed the corresponding column in database from vachar(32) to varchar(128),

Tried to change the values in wc-attribute-functions.php, and changed 28 to 128, but that didnt help..

// Validate slug.
if ( strlen( $slug ) >= 40 ) {
    /* translators: %s: attribute slug */
    return new WP_Error( ‘invalid_product_attribute_slug_too_long’, sprintf( __( ‘Slug “%s” is too long (40 characters max). Shorten it, please.’, ‘woocommerce’ ), $slug ), array( ‘status’ => 400 ) );
….

By now i am able to input a longer Attribute slug , but still get an error when saving..

screen

This is the error i get when trying to add a term to the test attribute ( with longer name)

enter image description here

here you can see i am able to create an attribute with a slug of 38 characters, however when i look in the mysql database in the "products_term_taxonomy" table, it does not show up there,

enter image description here

After changing 32 character limit to 128 in file taxonomy.php,now i can add terms to attribute.

enter image description here

And now visible also in database,

enter image description here

  • "but still get an error when saving" - What's the error? A client-side validation error, or an error generated by WordPress, or a database error passed back through WordPress, or something else? – Rup Aug 28 '19 at 11:40
  • Updated original question with error, as response to Rup – thijs thijs Aug 28 '19 at 11:58
  • Are these slugs used as taxonomies too then? There is a 32-character limit in register_taxonomy you might be running into. (That isn't AFAICS the code that makes new records though.) If not, I'd probably add trace to taxonomy_exists() and get_taxonomy() to see what the invalid value is. – Rup Aug 28 '19 at 12:07
  • Yes after changing , the 32-character limit to 128 in taxonomy.php as you said, now i can add terms to longer attribute names, no more error and it shows up in the database, will update my question with screens .. – thijs thijs Aug 28 '19 at 12:39
  • Great! Changing taxonomy.php is a core patch though, and in general that's frowned upon as it will get lost in an automatic update. I don't see anything you could hook into to change this limit otherwise though. – Rup Aug 28 '19 at 13:48
1

There is a solution for this.

  1. Manually create the long name attribute in "Product Attributes" page, and use a short slug name here. In the product import section there is no "attribute slug" in the Column Headers(Or maybe there is one but not used by WooCommerce by default).

    Like so

    enter image description here

    1. Then you can import from CSV files now. No need to change any code.

    Like so enter image description here

    enter image description here

    Hope this helps you.

| improve this answer | |
0

As discussed in the comments, the problem is that these slugs are also used as taxonomy names and there's a 32-character limit on taxonomy names in WordPress core. From register_taxonomy():

if ( empty( $taxonomy ) || strlen( $taxonomy ) > 32 ) {
    _doing_it_wrong( __FUNCTION__,
        __( 'Taxonomy names must be between 1 and 32 characters in length.' ), '4.2.0' );
    return new WP_Error( 'taxonomy_length_invalid',
        __( 'Taxonomy names must be between 1 and 32 characters in length.' ) );
}

We can't see any way to override this limit without patching core.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.