dsdfd2322 2019-07-13 12:03
浏览 92
已采纳

如何在图像中添加产品永久链接标签woocommerce购物车项目?

Please help to add product permalink at the image a tag, here is my code:

<?php
global $woocommerce;  $items = $woocommerce->cart->get_cart();
foreach($items as $item => $values) {
   $_product =  wc_get_product( $values['data']->get_id());

   //product image
   $getProductDetail = wc_get_product( $values['product_id'] );

   echo '<div class="cart-prd-img"><a href="'.esc_url( get_permalink( $product->id ) ).'">'.$getProductDetail->get_image().'</div>'; // accepts 2 arguments ( size, attr )
   echo '<div class="cart-prd-name">'.$_product->get_title().'</div>';  
    '<br> Quantity: '.$values['quantity'].'<br>';

   $price = get_post_meta($values['product_id'] , '_price', true);
        echo "  Price: ".$price."<br>";
} ?>
  • 写回答

1条回答 默认 最新

  • douhan9467 2019-07-13 12:56
    关注
    foreach($items as $item => $values) {
       $_product =  wc_get_product( $values['data']->get_id());
    
       //product image
       $getProductDetail = wc_get_product( $values['product_id'] );
    
       //get the id of product
       $product_id = $values['product_id'];
    
       //$product->id is null. to get the product link you have need to use valid product id - get_permalink( $product_id ) 
    
       echo '<div class="cart-prd-img"><a href="'.esc_url( get_permalink( $product_id ) ).'">'.$getProductDetail->get_image().'</div>'; // accepts 2 arguments ( size, attr )
       echo '<div class="cart-prd-name">'.$_product->get_title().'</div>';  
        '<br> Quantity: '.$values['quantity'].'<br>';
    
       $price = get_post_meta($values['product_id'] , '_price', true);
            echo "  Price: ".$price."<br>";
    } ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?