【发布时间】:2016-12-16 18:25:04
【问题描述】:
我的 PHP 代码是:
<ul class="minicart-content">
<?php foreach($woocommerce->cart->cart_contents as $cart_item_key => $cart_item): ?>
<li>
<a href="<?php echo get_permalink($cart_item['product_id']); ?>" class="product-image">
<?php $thumbnail_id = ($cart_item['variation_id']) ? $cart_item['variation_id'] : $cart_item['product_id']; ?>
<?php echo get_the_post_thumbnail($thumbnail_id, 'shop_thumbnail'); ?>
</a>
<div class="detail-item">
<div class="product-details">
<?php echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf( '<a href="%s" class="btn-remove" title="%s"><span></span></a>', esc_url( $woocommerce->cart->get_remove_url( $cart_item_key ) ), __( 'Remove this item', 'shoppystore' ) ), $cart_item_key ); ?>
<a class="btn-edit" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php esc_attr_e('View your shopping cart', 'shoppystore'); ?>"><span></span></a>
<p class="product-name">
<a href="<?php echo get_permalink($cart_item['product_id']); ?>"><?php echo esc_html( $cart_item['data']->post->post_title ); ?></a>
</p>
<div class="qty-number"><span><?php esc_html_e('Quantity: ', 'shoppystore'); ?> </span><?php echo esc_html( $cart_item['quantity'] ); ?></div>
</div>
<div class="product-details-bottom">
<span class="price"><?php echo $woocommerce->cart->get_product_subtotal($cart_item['data'], 1); ?></span>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
我正在使用该代码获取 img:
<img height="50px" width="50px" src="<?php
echo $cart_item['product_id']; $feat_image = wp_get_attachment_url( get_post_thumbnail_id($cart_item['product_id']) );
echo $feat_image;
?>">
我也尝试对 img 进行硬编码以进行测试
<img height="50px" width="50px" src="http://www.toys4all.pk/wp-content/uploads/2016/07/ttoys498_01_1600x1200QecQ.jpg" alt="message">
但它没有显示 img 或 alt 字符串。
【问题讨论】:
标签: php wordpress woocommerce cart product