In WooCommerce archive pages, the product image and the title are linked to the single-product page, like domain/product/{product-name}/.
I would like, if the product does not have a description for example, to remove that link.
I tried the following:
add_action("template_redirect", "disable_single_product_access", 1);
function disable_single_product_access() {
if (is_singular('product')) {
$product = wc_get_product(get_the_ID());
$has_variations = $product->is_type('variable');
$has_price = $product->get_price();
$has_description = $product->get_description();
if (!$has_variations || !$has_price || !$has_description) {
// If product has no description or something above remove redirection
exit;
}
}
}
I also tried:
- removing the
hrefand redirecting withwp_redirect, - setting the
hrefto redirect to an empty link.
None worked.