2014-10-11 56 views

回答

1

我一直在执行我的项目function.php 添加以下代码注销其添加视图购物车按钮的js一起添加到购物车按钮

wp_deregister_script('wc-add-to-cart'); 

wp_register_script('wc-add-to-cart', get_stylesheet_directory_uri(). '/js/add-to-cart-multi.js' , array('jquery'), WC_VERSION, TRUE); 

wp_enqueue_script('wc-add-to-cart'); 

现在,你需要调整的是js的那我们已经注销,现在我们需要一个名为add-to-cart-multi.js

一个新的js文件,下面的代码进入这个新创建的文件

jQuery(function($) { 

    // wc_add_to_cart_params is required to continue, ensure the object exists 
    if (typeof wc_add_to_cart_params === 'undefined') 
     return false; 

    // Ajax add to cart 
    $(document).on('click', '.add_to_cart_button', function(e) { 

     // AJAX add to cart request 
     var $thisbutton = $(this); 

     if ($thisbutton.is('.product_type_simple')) { 

      if (! $thisbutton.attr('data-product_id')) 
       return true; 

      $thisbutton.removeClass('added'); 
      $thisbutton.addClass('loading'); 

      var data = { 
       action: 'woocommerce_add_to_cart', 
      }; 

      $.each($thisbutton.data(), function(key, value) { 
       data[key] = value; 
      }); 

      // Trigger event 
      $('body').trigger('adding_to_cart', [ $thisbutton, data ]); 

      // Ajax action 
      $.post(wc_add_to_cart_params.ajax_url, data, function(response) { 

       if (! response) 
        return; 

       var this_page = window.location.toString(); 

       this_page = this_page.replace('add-to-cart', 'added-to-cart'); 

       if (response.error && response.product_url) { 
        window.location = response.product_url; 
        return; 
       } 

       // Redirect to cart option 
       if (wc_add_to_cart_params.cart_redirect_after_add === 'yes') { 

        window.location = wc_add_to_cart_params.cart_url; 
        return; 

       } else { 

        $thisbutton.removeClass('loading'); 

        fragments = response.fragments; 
        cart_hash = response.cart_hash; 

        // Block fragments class 
        if (fragments) { 
         $.each(fragments, function(key, value) { 
          $(key).addClass('updating'); 
         }); 
        } 

        // Block widgets and fragments 
        $('.shop_table.cart, .updating, .cart_totals').fadeTo('400', '0.6').block({ 
         message: null, 
         overlayCSS: { 
          opacity: 0.6 
         } 
        }); 

        // Changes button classes 
        $thisbutton.addClass('added'); 
        $thisbutton.addClass('hide'); 
        // View cart text 
        if (! wc_add_to_cart_params.is_cart && $thisbutton.parent().find('.added_to_cart').size() === 0) { 
         $thisbutton.after(' <a href="' + wc_add_to_cart_params.cart_url + '" class="add-cart button added_to_cart wc-forward" title="' + 
          wc_add_to_cart_params.i18n_view_cart + '"><i class="fa fa-shopping-cart"></i></a>'); 
        } 

        // Replace fragments 
        if (fragments) { 
         $.each(fragments, function(key, value) { 
          $(key).replaceWith(value); 
         }); 
        } 

        // Unblock 
        $('.widget_shopping_cart, .updating').stop(true).css('opacity', '1').unblock(); 

        // Cart page elements 
        $('.shop_table.cart').load(this_page + ' .shop_table.cart:eq(0) > *', function() { 

         $('.shop_table.cart').stop(true).css('opacity', '1').unblock(); 

         $('body').trigger('cart_page_refreshed'); 
        }); 

        $('.cart_totals').load(this_page + ' .cart_totals:eq(0) > *', function() { 
         $('.cart_totals').stop(true).css('opacity', '1').unblock(); 
        }); 

        // Trigger event so themes can refresh other areas 
        $('body').trigger('added_to_cart', [ fragments, cart_hash ]); 
       } 
      }); 

      return false; 

     } 

     return true; 
    }); 

}); 

线77号我已经用代码

$thisbutton.addClass('hide');

所以隐藏基本上都添加了class="hide"隐藏添加到购物车按钮

并做了一些更多的修改,我认为的代码,但我不记得它现在它是什么。

我希望这有助于有人

-1

我碰到这个偶然,而希望做eaxctly同样的事情,虽然我不能让JS的工作我也注意到在寻找增加.hide类宇补充道,当一旦类被添加到“添加到购物车”按钮,无论如何,所以添加以下到我的主题的CSS文件很好地做了这项工作。

a.button.product_type_simple.add_to_cart_button.ajax_add_to_cart.added { 
    display: none; 
} 

我再简单风格的“查看购物车”按钮出现在它的位置,以此来定位它:

a.added_to_cart { 
    //do your thing 
} 

希望是有帮助的人。

相关问题