WooCommerce更改单一产品链接

问题描述:

默认情况下,WooCommerce会创建一个产品页面链接,并在创建一个产品页面链接并将其添加到功能图像(以及标题)中。 我只想更改一个产品的链接,而不会影响其他产品。 在cart.php文件我看到这几行:WooCommerce更改单一产品链接

<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); 

我知道,如果我修改else行上<span class="product-thumbnail">节这一个:

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

我可以删除链接,但这对所有产品都有影响。

我该如何调用ID产品,然后更改其链接?我知道这将与$_product->id,但之后,我不知道如何或在哪里放置它。

PS:请原谅我的英语,谢谢。

+0

你知道你要惹 – RiggsFolly

+0

当然产品的'id'的'id'是606个 – Meyado

所以,你可以添加其他产品创建一个数组,目前只包含一个id,但谁知道什么样的未来带来

$special_products = array(606); 

然后,只需添加一个测试这个代码,然后任何你想要的输出,而不是这事之前

if (! $_product->is_visible()) { 
    echo $thumbnail; 
} else { 
    if (in_array($_product->id, $special_products)) { 
     echo 'Something else, whatever you like'; 
    } else { 
     printf('<a href="%s">%s</a>', $_product->get_permalink($cart_item), $thumbnail); 
    } 
} 
+0

非常感谢里格斯您的快速解答!我非常感激,但我认为我没有正确解释自己。 – Meyado

+0

我需要的是将用户带到另一个页面,而不是由一个WooCommerce创建。当您点击产品时,它会默认带您进入产品页面。我想改变这一点。没有其他的。 – Meyado

+0

那么你在'回声'里放了什么东西,不管你喜欢什么';或者是这个请求让我猜测你要发送给用户 – RiggsFolly