我已经获得了以下代码来从woocommerce购物车中获取元素,但我也无法弄清楚如何删除该项目的链接。你能帮我吗?
<div class="carters">
<?php
$subtotal = WC()->cart->get_cart_subtotal(); echo $subtotal;
foreach( WC()->cart->get_cart() as $cart_item ){
$product_id = $cart_item['data']->get_id();
$qty = $cart_item['quantity'];
$price = $cart_item['data']->get_price();
$thumbnail = get_the_post_thumbnail_url( $product_id );
echo '<img width="50px" src="' . $thumbnail . '" />';
$title = get_the_title( $product_id );
echo $title . $qty . $price;
}
?>
</div>
答案 0 :(得分:1)
可以通过这种方式使用wc_get_cart_remove_url( $cart_item_key )
函数:
<div class="carters">
<?php
$subtotal = WC()->cart->get_cart_subtotal(); echo $subtotal;
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ){
$product_id = $cart_item['data']->get_id();
$qty = $cart_item['quantity'];
$price = $cart_item['data']->get_price();
$thumbnail = get_the_post_thumbnail_url( $product_id );
echo '<img width="50px" src="' . $thumbnail . '" />';
$title = get_the_title( $product_id );
echo $title . $qty . $price;
// get the cart remove url (since WooCommerce 3.3)
$cart_item_remove_url = wc_get_cart_remove_url( $cart_item_key );
}
?>
</div>
经过测试并可以在Woocommerce 3.3+上使用
因此,在woocommerce 3.3之前,您将改为使用:
WC()->cart->get_remove_url( $cart_item_key );