Ser*_*ili 2 php url wordpress cart woocommerce
我有下面的代码来从 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>
Run Code Online (Sandbox Code Playgroud)
有一个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>
Run Code Online (Sandbox Code Playgroud)
经过测试并适用于 Woocommerce 3.3+
因此,在 woocommerce 3.3 之前,您将使用:
WC()->cart->get_remove_url( $cart_item_key );
Run Code Online (Sandbox Code Playgroud)