在 Woocommerce 3.3 中获取购物车项目删除 URL

Get Cart Item Remove URL in Woocommerce 3.3

我有以下代码从 woocommerce 购物车中获取元素,但我不知道如何获取 删除 link 的项目 作为出色地。你能帮帮我吗?

<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>

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+

It replace deprecated WC_Cart method get_remove_url( $cart_item_key )

所以在 woocommerce 3.3 之前你将使用:

WC()->cart->get_remove_url( $cart_item_key );