简体   繁体   English

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

[英]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.

相关问题 如何将购物车商品产品重定向到Woocommerce中的特定页面? - How can i redirect cart item product to specific page in Woocommerce? 向 Woocommerce 购物车项目添加溢出和标题标签 - Add overflow and title tag to Woocommerce cart item 在 Woocommerce 购物车页面中的购物车项目名称后添加产品 ID - Add the product ID after the cart item name in Woocommerce cart page 结合 WooCommerce 中的多个购物车项目永久链接更改 - Combining multiple cart item permalink changes in WooCommerce 为 WooCommerce 中特定产品类别的购物车项目自动添加产品 - Auto add a product for cart item from specific product categories in WooCommerce Woocommerce:如何将产品从 iframe 添加到购物车? - Woocommerce: how to add a product from iframe to the cart? 如何以编程方式将可预订产品添加到woocommerce购物车? - How to add a bookable product to woocommerce cart programmatically? 将Woocommerce产品图片和“添加到购物车”链接到产品页面 - Linking Woocommerce product image and 'add to cart' to product page 如何将每个产品作为新商品添加到购物车 - How can I add every product as a new item into cart 根据Woocommerce中购物车的数量增加产品价格的额外成本 - Add an extra cost to product price based on cart item count in Woocommerce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM