Woo commerce change a single product link

3

By default, WooCommerce creates a link in both the image and the product title when it is created, which takes you to its own page. My intention is to change this link to take the client to another page where you can add designs to that product.

The code to change is this, in the file "cart.php"

<td class="product-name">
    <?php // Avada edit ?>
    <span class="product-thumbnail">
    <?php
         $thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );

         if ( ! $_product->is_visible() )
             echo $thumbnail;
         else
             printf( '<a href="%s">%s</a>', _product->get_permalink( $cart_item ), $thumbnail );
    ?>
    </span>
    <div class="product-info">
    <?php
        if ( ! $_product->is_visible() )
            echo apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key );
        else
            // Avada edit
            echo apply_filters( 'woocommerce_cart_item_name', sprintf( '<a class="product-title" href="%s">%s</a>', $_product->get_permalink( $cart_item ), $_product->get_title() ), $cart_item, $cart_item_key );

If I'm not wrong to remove any link I have to manipulate the else of the section <div class="product-info"> by this line:

sprintf( '%s', $_product->get_title() ), $cart_item, $cart_item_key );

Here's my question: How do I call the product to which I want to change your link with $_product->id ?? I do not know where to put it in the function or how to change the link without pifiarla ...

Thank you!

    
asked by Meyado 12.05.2016 в 15:37
source

1 answer

1

It would be a matter of using the apply_filters that is available. Something of the genre:

add_filter( 'woocommerce_cart_item_name', 'apply_filter_9741', 10, 3 );

function apply_filter_9741( $title, $item, $item_key ) {
    $el_enlace = 'http://example.com/enlance/';
    $nuevo_enlace = sprintf('<a href="%s">%s</a>', $el_enlace, $title);
    return $nuevo_enlace;
}

This post in Stack Overflow explains how to use $item and $item_key to extract extra information from the cart: Get cart item name, quantity all details woocommerce

    
answered by 05.05.2017 в 20:45