• Resolved yigitataman

    (@yigitataman)


    Hello everyone.

    My problem appears to be simple but I haven’t been able to solve it. (Actually I don’t even know if this a WooCommerce issue or a Woostify issue). On my product archive page I display product tags on product cards. However, the order of the tags is not the same as what I enter. For example, I set 3 product tags, A, B, C, but they are displayed as B, C, A. Even when I enter them as C,A,B (thinking that the first one flies off to the end) they are still displayed as BCA. I both edited and quick edited the tags, left and removed spaces between commas, left and removed a comma at the end of the tag sequence but nothing changes (they are displayed in the wrong order even in the WooCommerce All Products interface). These tags are actually author names and their order is important. What is the problem here and how can I solve it? (Interestingly this is not the case for all multiple-tagged products, only a few of them has the problem.)

    Any help is greatly appreciated. Thank you in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter yigitataman

    (@yigitataman)

    With a little thinking it becomes obvious that they are ordered alpahbetically *facepalm* Is there any way to get them to be ordered in the way we want or are they ordered thus by unchangeable default?

    Thread Starter yigitataman

    (@yigitataman)

    I was able to get the job done. I am pasting the code here as well so if other people want the same thing they can make use of this weirdly solo thread.

    This was a template-ish snippet e-mailed to me by a rookie WP developer. And I am less than rookie in adapting these things to my needs, so bear with me if this code impractically scratches the left ear with the right hand over the head.

    The following goes in your functions.php file. (I am aware that you are advised against adding code there but what can you do?)

    function plugin_get_the_ordered_terms ( $terms, $id, $taxonomy ) {
        if ( 'product_tag' != $taxonomy )
            return $terms;
    
        $terms = wp_cache_get($id, "{$taxonomy}_relationships_sorted");
        if ( false === $terms ) {
            $terms = wp_get_object_terms( $id, $taxonomy, array( 'orderby' => 'term_order' ) );
            wp_cache_add($id, $terms, $taxonomy . '_relationships_sorted');
        }
    
        return $terms;
    }
    
    add_filter( 'get_the_terms', 'plugin_get_the_ordered_terms' , 10, 4 );
    
    function plugin_register_sorted_product_tag () {
        register_taxonomy( 'product_tag', 'product', array( 'sort' => true, 'args' => array( 'orderby' => 'term_order' ) ) );
    }
    
    add_action( 'init', 'plugin_register_sorted_product_tag' );

    Cheers.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Product tag sequence’ is closed to new replies.