Archived topic
Sold out label not showing
5 replies · Started by chris on January 16, 2021
Hi im using this snippet to display a sold out label, but whatever i try it doesn't want to work.
Snippet
add_action( 'woocommerce_before_shop_loop_item_title', 'bbloomer_display_sold_out_loop_woocommerce' );
function bbloomer_display_sold_out_loop_woocommerce() {
global $product;
if ( ! $product->is_in_stock() ) {
echo '<span class="soldout">Sold Out</span>';
}
}
CSS
.soldout {
padding: 3px 8px;
text-align: center;
background: #222;
color: white;
font-weight: bold;
position: absolute;
top: 6px;
right: 6px;
font-size: 12px;
}
Any thoughts?
Hi Chris,
I don't see any issue with this filter or the CSS.
Could you let me know which product is out of stock? I could have a look for you.
Let me know :)
I have a feeling it's something to do with GP because when not on the page i built and im on a woo categories page i see out of stock and sale labels.
Is there a way to make them display on the page i built too?
Also how would i hide the sale label IF product is out of stock?
Thank you..
Hi Chris,
It's clearly not a GP issue, but I'm happy to point you the right direction.
It's because the Woocommerce filter (PHP) you are using is only targeting the default Woocommerce index pages, NOT including the static pages built with Woocommerce block.
The solution for you would be try to find another Woocommerce filter which targets the Woocommerce block.
Hi, I'm at a loss with that.. Sorry.
I have looked how to target blocks but no one seems to be having the same issue.
The sale tag which woo makes when a product is on sale, again doesn't display in blocks?
So would i need a new filter for "Sale" and "Out of stock" to make them both display on blocks?
Absolutely at a loss right now..
I'm not very familiar with Woocommerce block, but I believe show the "sale" tag is a default setting, and your shop page is showing the sale tag above product price.
I think you just need to find a filter that add "Sold out" tag to woocommerce block's product title.