简体   繁体   English

从购物车中删除WooCommerce项目

[英]Delete WooCommerce Item From Cart

Looking to remove an item from a custom mobile cart in Woocommerce. 希望从Woocommerce中的自定义移动购物车中删除商品。

<div class="mobile-cart-pop-out-menu-items">
    <ul>
      <?php global $woocommerce;
      $items = $woocommerce->cart->get_cart();
      foreach($items as $item => $values) { ?>
            <? $_product = $values['data']->post; ?>
            <li>
              <h3>X</h3>
              <h4><? echo $_product->post_title; ?></h4>
              <h5><? $price = get_post_meta($values['product_id'] , '_price', true);echo "£".$price; ?></h5>
            </li>
      <?php } ?>
    </ul>
</div><!--ends items-->

I want to be able to click the X to remove that item from the cart, but cant find any code snippets or help to work out how to do this. 我希望能够单击X将其从购物车中删除,但找不到任何代码段或无法确定如何执行此操作。

The woocommerce template located in templates/cart/cart.php shows you how to do this. 位于templates / cart / cart.php中的woocommerce模板向您展示了如何执行此操作。

<?php
    // @codingStandardsIgnoreLine
    echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
        '<a href="%s" aria-label="%s" data-product_id="%s" data-product_sku="%s"><i class="pe-7s-close"></i></a>',
        esc_url( wc_get_cart_remove_url( YOURCARTITEMID ) ),
        __( 'Remove this item', 'woocommerce' ),
        esc_attr( $values['product_id'] ),
        esc_attr( $_product->get_sku() )
    ), YOURCARTITEMID );
?>

Is the code you need to generate the delete from cart link. 是您要生成从购物车链接中删除的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM