not showing label when other label is active
-
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.
-
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
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
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
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 patiencehow 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}
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 patienceSo 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; }
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?
You need to use condition
if ( $label_id === 4296 && is_archive() ) { return false; }
not the
if ( $label_id === 4296 ) { return false; }
Not work, anything changed, the label is still showing up on archive.
maybe another solution?
In fact this code must work. Please make sure that the cache for any caching plugins is cleared.
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?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
- The topic ‘not showing label when other label is active’ is closed to new replies.