WooCommerce Ajax购物车页面-禁用“删除项目"(红色图标&"X&"按钮) [英] WooCommerce ajax cart page - Disable "remove item" (red icon "X" button)

查看:75
本文介绍了WooCommerce Ajax购物车页面-禁用“删除项目"(红色图标&"X&"按钮)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WooCommerce ajax购物车页面中,我尝试使用以下方法来分离默认的javascript事件,以删除添加的项(带有叉的红色小图标):

In WooCommerce ajax cart page, I have tried to detach default javascript event for removing added items (the little red icon with a cross) using:

$(".remove").off("click"); 

$(".remove").unbind("click"); 

但这没用.

我尝试执行此操作的主要原因是,在标题中,我有一个自定义菜单购物车图标,上面带有产品编号通知.而且我不能通过WooCommerce ajax来更新此通知号,而只能刷新页面.

The main reason why I am trying to do this is because, in header, I have a custom menu cart icon with product number notification on it. And I can't either get this notification number updated through WooCommerce ajax, but only refreshing page.

如何禁用此javascript事件?或者如何使我的通知脚本与ajax一起使用?

How can I disable this javascript event? Or How can I make my notification script working with ajax?

这是我的菜单车代码:

<div id="expanded-menucart"> 

<?php  

foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {

    ?>

    <div class="one-menucart-item">

        <?php 

        $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
        $thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );
        $product_subtotal = apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity']), $cart_item, $cart_item_key );
        $quantity = $_product->get_stock_quantity();
        $antal = $cart_item['variation']['attribute_antal']; 
        $productid = $cart_item['product_id']; 

        echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
            '<a href="%s" class="remove, cart-remove" title="%s" data-product_id="%s" data-product_sku="%s">&times;</a>',
            esc_url( WC()->cart->get_remove_url( $cart_item_key ) ),
            __( 'Remove this item', 'woocommerce' ),
            esc_attr( $product_id ),
            esc_attr( $_product->get_sku() )
            ), $cart_item_key ); 

        echo $thumbnail; ?>
        <a id="<?php $productid; ?>" href="<?php the_permalink($productid); ?>"> <?php echo $cart_item['data']->post->post_title;?></a><br><br><?php
        echo $antal;
        echo $product_subtotal;?><br>

    </div><?php
}
?>
<?php global $woocommerce; ?>

    <p>TOTAL:
        <a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>"><?php echo $woocommerce->cart->get_cart_total(); ?></a></p><br>

    <?php if ( WC()->cart->get_cart_contents_count() != 0 ) { ?>

        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="menucart-checkout">
                    <a href="<?php get_home_url(); ?>/fcb/checkout">TILL CHECKOUTEN</a>
                </div>
            </div>
        </div>

    <?php } ?>

    </div>

pastebin上的外部来源: http://pastebin.com/7rXuBQPj

External source on pastebin: http://pastebin.com/7rXuBQPj

谢谢.

推荐答案

因此,只有在您进入购物车页面时,您的问题才会出现,因为在这种情况下,您有2个购物车:

So your problem is only when you are in cart page because in this case you have 2 carts:

  • 标题中有一个迷你购物车(带有通知,但没有数量按钮).
  • 您的页面中有普通购物车的内容(没有该通知,但带有数量按钮).

所以他们有冲突,这很正常.您将不得不在它们之间进行选择.

So they are in conflict and that is normal. You will have to chose between them.


问题:您真的需要像购物车页面上的这种微型购物车吗?


The question: Are you really needing this mini-cart as it is on cart page?

2个解决方案:

  1. 例如,要仅在商品数量上在购物车页面上使用轻型迷你购物车版本(避免冲突和实时刷新商品(删除ajax)).或者,您可以在购物车页面上完全禁用.为此,您可以使用条件 is_cart() .

  1. To have a light mini cart version on cart page (avoiding conflicts and live refreshing items (ajax remove)) only with item count, for example. Or you could disable it completely for cart page. You could use the conditional is_cart() for this purpose.

要绕过购物车页面(要困难得多),将缺少的功能扩展到实际的微型购物车:

To bypass cart page (much more difficult) extending missing functionalities to your actual mini-cart:

  • 按物料行添加数量按钮
  • 添加可选的优惠券字段功能

在第2种情况下,您将不得不将客户重定向到结帐,这是某些WooCommerce商店的经典行为.

In case 2 you will have to redirect customer to checkout, what is a classic behavior on some WooCommerce shops.

这篇关于WooCommerce Ajax购物车页面-禁用“删除项目"(红色图标&amp;"X&amp;"按钮)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆