S
S
Sergey Shkurikhin2020-06-28 15:12:18
WordPress
Sergey Shkurikhin, 2020-06-28 15:12:18

How to wrap product card images into a link to this product?

How to make product card images in categories clickable. The theme had a quick preview feature that didn't work correctly. After turning it off, the link of the cards flew off.

How to wrap the required module in links? Where to find it and what to prescribe?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Litvinenko, 2020-06-28
@shkyrikhin99

You have a theme and you will most likely have to dig deeper into it to find the necessary functions.
In the screenshot, something is clearly not
5ef8d628e37ce884941428.png
standard in woocommerce, the opening link tag hangs on the hook at the 10th priority and the code of this function is displayed by the function
do_action( 'woocommerce_before_shop_loop_item' );
woocommerce_template_loop_product_link_open()

if ( ! function_exists( 'woocommerce_template_loop_product_link_open' ) ) {
  /**
   * Insert the opening anchor tag for products in the loop.
   */
  function woocommerce_template_loop_product_link_open() {
    global $product;

    $link = apply_filters( 'woocommerce_loop_product_link', get_the_permalink(), $product );

    echo '<a href="' . esc_url( $link ) . '" class="woocommerce-LoopProduct-link woocommerce-loop-product__link">';
  }
}

replacing the opening tag in standard woocommerce could look something like this:
remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
add_action( 'woocommerce_before_shop_loop_item', 'custom_open_link', 10 );
function custom_open_link() {
  ?>
    <a href="<?php the_permalink() ?>">
  <?php
}

S
Sergey Shkurikhin, 2020-06-28
@shkyrikhin99

https://blagomart.ru/index.php/product-category/decor/
An example of a page with a non-clickable product

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question