[英]How can add product permalink in image a tag woocommerce cart item?
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>";
} ?>
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>";
} ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.