I am running an art gallery website using WooCommerce and the owner does not want to show the product name/title if the product has been sold/out of stock.
I have got this far with putting together a function, but it doesn’t work. I wondered if anyone could give me any tips?
// Hides title on Sold products
add_filter( 'woocommerce_shop_loop_item_title', 'remove_name', 10, 2 );
function remove_name ( $product ) {
if ( ! $product->is_in_stock()) {
$title = '';
}
return $title;
}
3
Answers
Please try to use this hook to remove product title. Use this inside the condition to check if product is in stock:
This does what you want but still allows access to the product page.
Your code contains some errors and mistakes:
woocommerce_shop_loop_item_title
is NOT an filter but an action hook$product
is undefined, useglobal $product;
So you get: