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

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

问题描述

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

  $(。remove)。off( click); 

  $(。remove)。unbind( click); 

但这没用。



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



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



这是我的菜单代码:



< pre class = lang-php prettyprint-override> < 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)),
__('删除此商品','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全球$ woocommerce; ?>

< p>总计:
< 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



谢谢。

解决方案

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




  • 标头中有一个微型购物车(带有通知,但没有数量按钮)。

  • 您的页面中包含普通购物车(没有)该通知,但带有数量按钮)。




所以它们是冲突的,这很正常。您必须在它们之间进行选择。







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



2种解决方案:


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


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




    • 按物料行添加数量按钮

    • 添加可选的优惠券字段功能


2您将不得不将客户重定向到结帐,这是某些WooCommerce商店的经典行为。


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"); 

Or

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

But it didn't work.

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.

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

Here is my menucart code:

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

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

Thanks.

解决方案

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

  • You have a mini cart kind of in your header (with notification, but without quantity buttons).
  • You have in page content your normal cart (without that notifications, but with quantity buttons).

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

  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.

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

    • Adding quantity buttons by items line
    • Adding optional coupon field functionality

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

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

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