Forum Replies Created

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter charlieadmino

    (@charlieadmino)

    Si immagino non abbia senso fare un aggiornamento solo per questa cosa. Al massimo verifico dove si trova nel codice del plugin e me la correggo a mano, temporaneamente!

    Grazie davvero.

    Thread Starter charlieadmino

    (@charlieadmino)

    Mi perdoni per la mancata risposta, grazie ancora, sono riuscito a utilizzare il tutto, su due siti!

    Non so come mai in uno dei siti, la selezione è immediata mentre nell’altro, una volta selezionata una voce dalla tendina, rimanga fermo 1 secondo circa. Entrambi i siti hanno la stessa versione WordPress.

    Ad ogni modo volevo solo segnalarle che “Seleziona una provincia::” ha due volte i “:”

    Grazie ancora!

    Thread Starter charlieadmino

    (@charlieadmino)

    @bcworkz

    “There’s a distinct term slug provided with every item!? That’s useful 😀”

    Well, I discovered that WordPress does it on its own.
    Tried to add manually another material “Opal” and sub-category “Small”.
    The slug got automatically “opal-small”.

    “You’re right, relating images to terms is another topic.” I knew I didn’t explain myself correctly.

    These medals are special products since in the e-commerce there’s a special drang and drop area where you can upload a custom image to be printed on the medal itself.
    We managed this with a plugin.

    In the WordPress admin panel, you have a field (in the plugin settings) to specify for which product categories have to be displayed this upload area in the product page.
    So the word “Medals” is in this text field.

    Issue is that, on every import, the category “Medals” (like every other category) is deleted and created again. So this plugin is, of course, not intended to dinamically search that category again in the db.

    That means every morning I find this field emply and have to manually specify again “Medals” and hit “Save”.

    Was looking for a way to make a CRON process and insert “Medals” term after the import every night. Tried to ask the plugin dev but didn’t answer. Tried to look if there’s a table in the DB containing this text field but with no luck. It seems something Javascript stored(?) but I’m not able to edit the plugin.

    So yeah this is the minor issue now.

    Thread Starter charlieadmino

    (@charlieadmino)

    @bcworkz

    I’ll be damned…”It just works” -Todd Howard

    Ok for sure not the best solution but still better than having to set categories manually every morning.

    This time I tested in on the live site. Everything is fine.

    Now the only thing missing is that these medals have an Upload file customizer for printing your own image on it, and since categories are deleted and reinserted every night, I lose them in the specific configurator field on the admin panel…have to figure out how to automatically re-add them at the end of every import, but that’s a whole new thread.

    As for subcategories here, I cannot think of a better solution for now. Don’t really understand how cache will come in handy.

    Thread Starter charlieadmino

    (@charlieadmino)

    @bcworkz

    Yes, it seems that new taxonomic structure is created on every import.

    You know what? I saw that for example the category “Small” under “Bronze” has slug “small”, while for example “Small” under “Gold” has a “small-gold” slug.

    Is there a function to set product/post category knowing the category slug?

    I’m reading that “wp_set_object_terms” can have slug term, instead of using category ID.

    That may solve this issue but I don’t seem to find a function like that around.

    What do you think?

    Thread Starter charlieadmino

    (@charlieadmino)

    @bcworkz

    I mean that with every new category created, my client calls me. I explicitly asked them for that.

    After using those new lines of code in the test website, I decided to use them in the live one.

    But it seems my efforts are still useless. When testing I used a short CSV (for low import time) containing only medals.
    In the real website, I have all their actual products, and when importing, the category IDs are changed every time.

    So yeah, not even this code works.

    Also, well I studied arrays in the past and used them. But nothing like multi-dimensional + nested array. Probably too complex for me.

    But as reported here, been able to use that array won’t be of any help, since IDs change on every import.

    Thread Starter charlieadmino

    (@charlieadmino)

    @bcworkz

    well about the drawback, the client will notice me if there gonna be new categories, so no problem. I can’t find another solution for now.
    I’m sure I saw other posts around reporting this issue but they solved it in another way specific for their situation.

    Well, I tried to check $cat == “medaglie” in the past but it didn’t work, don’t really know why. Will try again. Maybe I’m missing a specific string checker function.

    Also, I check for “medaglie” because even other products may have “argento” or something like that so I want to be sure it is affecting only medals.

    About the multi-dimensional nested array…well, I’m not that skilled and I have multiple doubts about it. Will try to read multiple times and test if I’m able to use it.

    Thanks a lot for the kind help.

    Thread Starter charlieadmino

    (@charlieadmino)

    I’m sorry. “medaglie” is “Medals” and “argento” is “Silver”.

    Thread Starter charlieadmino

    (@charlieadmino)

    @bcworkz

    I tested and when importing again, the category ID is always the same, so I might try to make “if” conditions with a fixed ID just for medals categories.

    After searching a lot even today, I have changed the code in:

    
    $cat = sanitize_text_field($data[2]);
    $cat = strtolower($cat);
    $cat2 = sanitize_text_field($data[3]);
    $cat2 = strtolower($cat2);
    $cat3 = sanitize_text_field($data[4]);
    $cat3 = strtolower($cat3);
    wp_set_object_terms($post_id, $cat, ‘product_cat’);
    wp_set_object_terms($post_id, $cat2, ‘product_cat’, $append = true ) ;
    
    if ( has_term( 'medaglie', 'product_cat', $post_id ) ) {
    				if ( has_term( 'argento', 'product_cat', $post_id ) ) {
    					wp_set_object_terms($post_id, 589, 'product_cat', $append = true );
    				}
    				else {
    					wp_set_object_terms($post_id, $cat3, 'product_cat', $append = true );
    				}
    			}
    

    Where 589 is the ID of “Small” under “Silver”.
    I have to make more if conditions and even one to check where to give 589 or “Large” ID.

    Is it similar to what you were thinking about?

    I don’t think this is the best solution but it seems to work for “Silver”.
    I’m sorry if I’m missing out a lot and not able to understand. This whole thing gives me a lot of confusion.

    Thread Starter charlieadmino

    (@charlieadmino)

    @bcworkz

    Yes, $data[3] term’s parent IS ALWAYS $data[2]

    For example, $data[2] is “Medals”, $data[3] is “Silver” and $data[4] is “Large”
    otherwise, it would mess up categories and subcategories while creating the product.

    I don’t really know how to do such a query. The code is executed for every CSV because every row is a single product.

    Our server is powerful and kinda low on load atm so it may not be so demanding to do such a query.

    Thanks a lot for answering and for formatting my code.

Viewing 10 replies - 1 through 10 (of 10 total)