Remove product link from WooCommerce archives if the product has no description

28 views Asked by At

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 href and redirecting with wp_redirect,
  • setting the href to redirect to an empty link.

None worked.

0

There are 0 answers