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

时间:2019-07-13 12:03:54

标签: php wordpress

请帮助在图片的标签上添加产品永久链接,这是我的代码:

<?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 个答案:

答案 0 :(得分:0)

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>";
} ?>