• Resolved nimavi

    (@nimavi)


    Hi, awesome plugin. maybe is there a way to hide a label when other label is “active” on the same product. Like a label condition, I tried with apply_filters- awl_show_label_for_product but I don’t know where to find the labels IDs. Please help.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    Hi,

    Well you can just go to the plugin settings page and find ‘Max. number of labels per product’ option. Set it to ‘1’ so only one label will be shown per product.

    Regards

    Thread Starter nimavi

    (@nimavi)

    sorry, that is not what I want, for example:
    I have 3 labels on product: 1, 2, 3 (with conditions)
    I want like a condition, if it shows label 1, not showing label 3, but alway show label 2. if label 1 is not showing, then show label 3.

    Maybe using apply_filters- awl_show_label_for_product or something

    Plase help

    Plugin Author ILLID

    (@mihail-barinov)

    Well in this case you can use code like this:

    class AWL_Labels_Conditions {
        public $labels = array();
        public function __construct() {
            add_filter( 'awl_show_label_for_product', array( $this, 'awl_show_label_for_product' ), 10, 3 );
        }
        public function awl_show_label_for_product( $match_condition, $product, $label_id ) {
            if ( $match_condition ) {
                $product_id = $product->get_id();
                $this->labels[$product_id][$label_id] = $label_id;
                // your conditions below
                if ( isset( $this->labels[$product_id]['1'] ) && $label_id === 3 ) {
                    return false;
                }
            }
            return $match_condition;
        }
    }
    new AWL_Labels_Conditions();

    this code hide labels with ID = 3 if product already display the label with ID = 1. Edit the code as you need.

    Regards

    Thread Starter nimavi

    (@nimavi)

    Thanks so much, but I see it is a little more complicated than I thought, besides only need that in archive… to simplify, with code, how can I hide a specific label on archive only (it doesn’t matter the product) and where can I find the label IDs?
    I appreciate so much your help and patience

    • This reply was modified 3 years ago by nimavi.
    • This reply was modified 3 years ago by nimavi.
    Plugin Author ILLID

    (@mihail-barinov)

    how can I hide a specific label on archive only (it doesn’t matter the product)

    In this case code can looks like that:

    class AWL_Labels_Conditions {
        public $labels = array();
        public function __construct() {
            add_filter( 'awl_show_label_for_product', array( $this, 'awl_show_label_for_product' ), 10, 3 );
        }
        public function awl_show_label_for_product( $match_condition, $product, $label_id ) {
            if ( $match_condition ) {
                if ( is_archive() ) {
                    $this->labels['archive'][$label_id] = $label_id;
                    // your conditions below
                    if ( isset( $this->labels[$product_id]['1'] ) && $label_id === 3 ) {
                        return false;
                    }
                }
            }
            return $match_condition;
        }
    }
    new AWL_Labels_Conditions();

    and where can I find the label IDs?

    Just open label edit page and look on its URL. You will find id inside post parameter like ?post={ID}

    Thread Starter nimavi

    (@nimavi)

    Hi there,

    thanks for your support, the solution kinda works, but this: “$match_condition” and “if ( isset( $this->labels[$product_id][‘1’]” gives me problems, I dont know why that code?
    Please, I Just need Hide a label on archive, I don’t need other conditions. Just Hide a label.
    In other words, I got a label with ID 4296, I just don’t want it to show up on archive, No more.
    Again, I appreciate so much your help and patience

    • This reply was modified 3 years ago by nimavi.
    • This reply was modified 3 years ago by nimavi.
    Plugin Author ILLID

    (@mihail-barinov)

    So just use following code:

    add_filter( 'awl_show_label_for_product', 'my_awl_show_label_for_product', 10, 3 );
    function my_awl_show_label_for_product( $match_condition, $product, $label_id ) {
        if ( $label_id === 4296 && is_archive() ) {
            return false;
        }
        return $match_condition;
    }
    Thread Starter nimavi

    (@nimavi)

    thanks, but, that code not work, the label is still showing up…
    I tried:
    if ( $label_id === 4296 ) {
    return false;
    }
    return $match_condition;

    this way the label no longer appears anywhere and I need to see it on the product page.

    Any thoughts?

    Plugin Author ILLID

    (@mihail-barinov)

    You need to use condition

     if ( $label_id === 4296 && is_archive() ) {
            return false;
        }

    not the

    if ( $label_id === 4296 ) {
    return false;
    }
    Thread Starter nimavi

    (@nimavi)

    Not work, anything changed, the label is still showing up on archive.

    maybe another solution?

    Plugin Author ILLID

    (@mihail-barinov)

    In fact this code must work. Please make sure that the cache for any caching plugins is cleared.

    Thread Starter nimavi

    (@nimavi)

    I used W3 Total Cache plugin to purge All Caches but the label is still displayed on archive, maybe other solution to clear the cache?
    I use elementor plugin in my site, and the condition to display that label is to be a elementor block, maybe that can cause the problem?

    Plugin Author ILLID

    (@mihail-barinov)

    Yes, this can be a reason. So for your label with ID 4296 remove all display conditions. Leave just something like:

    Stock status -> Equal to -> In stock

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘not showing label when other label is active’ is closed to new replies.