Woocommerce购物车小部件不显示任何内容


Woocommerce Cart widget displays no content

我将woocommerce购物车小部件添加到我的侧边栏中,由于主题和woocommerce行为的一些自定义,我将这行代码添加到了我的主题函数中.php:

remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );

当此行处于活动状态时,不会显示购物车内容,仅显示小部件标题。当我注释掉这一行时,购物车中的商品将显示在单个产品页面和商店页面上。请参阅标记:

<div id="secondary" class="widget-area" role="complementary">
        <aside id="woocommerce_widget_cart-12" class="widget woocommerce widget_shopping_cart">
            <h3 class="widget-title">Winkelmand</h3>
            <div class="widget_shopping_cart_content">
               <ul class="cart_list product_list_widget ">
                  <li>
                      <a href="http://localhost/?product=flying-ninja">
                         <img width="600" height="600" src="//localhost/wp-content/uploads/2013/06/poster_2_up-600x600.jpg" class="attachment-shop_thumbnail wp-post-image" alt="poster_2_up">Flying Ninja                      </a>
                         <span class="quantity">1 × <span class="amount">€12,00</span></span>                   
                  </li>
                  <li>
                      <a href="http://localhost/?product=patient-ninja">
                         <img width="600" height="600" src="//localhost/wp-content/uploads/2013/06/hoodie_3_front-600x600.jpg" class="attachment-shop_thumbnail wp-post-image" alt="hoodie_3_front">Patient Ninja                       </a>                    
                         <span class="quantity">1 × <span class="amount">€35,00</span></span>                       
                  </li>
                  <li>
                      <a href="http://localhost/?product=photo-3">
                          <img width="399" height="600" src="//localhost/wp-content/uploads/2014/12/DSC07870-399x600.jpg" class="attachment-shop_thumbnail wp-post-image" alt="SONY DSC">Photo 3                        </a>
                          <span class="quantity">1 × <span class="amount">€15,00</span></span>                  
                  </li>
               </ul><!-- end product list -->
<p class="total"><strong>Subtotaal:</strong> <span class="amount">€62,00</span></p>
<p class="buttons">
    <a href="http://localhost/?page_id=334" class="button wc-forward">Winkelmand bekijken</a>
    <a href="http://localhost/?page_id=335" class="button checkout wc-forward">Afrekenen</a>
</p>
</div>
</aside>
</div>

如您所见,所有产品都已显示,按钮也出现了。但是,它们不会显示在所有其他页面上。在这些页面上,仅显示小组件标题。在这些页面上,标记如下所示:

<div id="secondary" class="widget-area" role="complementary">
    <aside id="woocommerce_widget_cart-12" class="widget woocommerce widget_shopping_cart">
        <h3 class="widget-title">Winkelmand</h3>
            <div class="widget_shopping_cart_content">
            </div>
    </aside>        
</div>

我的问题是:为什么remove_action行代码会干扰购物车小部件的内容?为什么其他页面上的div class="widget_shopping_cart_content">为空,无论remove_action行是否被注释掉。

我发现这与我的定制有关。当我使用标准的二十二主题时(在我的子主题是构建的(上,它工作正常。

编辑

当然,我正在搜索自己,并能够进一步缩小范围。原因是在我的主题功能中的这个功能中.php但我不知道它有什么问题,我应该怎么做。

function twentytwelve_child_masonry() {
if (!is_admin()) {
    wp_enqueue_script('masonry');
    add_action('wp_footer', 'twentytwelve_child_add_masonry');      
    function twentytwelve_child_add_masonry() { ?>
        <script>
                    (function( $ ) {
                        "use strict";
                        $(function() {
                        //set the container that Masonry will be inside of in a var
                        var container = document.querySelector('.products');
                        //create empty var msnry
                        var msnry;
                        // initialize Masonry after all images have loaded
                        imagesLoaded( container, function() {
                            msnry = new Masonry( container, {
                                itemSelector: '.product',
                                isAnimated: true
                            });
                        });
                        });
                        }(jQuery));
        </script>
    <?php 
    }
}
}
add_action('init', 'twentytwelve_child_masonry');

我正在拔头发.....我现在正在尝试解决这个问题一周。请帮忙!?

编辑 2

当我尝试调试项目时,我收到以下消息:

TypeError: 'null' is not an object (evaluating 'a.length') (15:45:27:306 | error, javascript)
at f (http://localhost/wp-includes/js/masonry.min.js?ver=3.1.2:1:28901)
at g (http://localhost/wp-includes/js/masonry.min.js?ver=3.1.2:1:29105)
at g (http://localhost/wp-includes/js/masonry.min.js?ver=3.1.2:1:29031)
at (anonymous function) (http://localhost/?product=happy-ninja:262:40)
at j (http://localhost/wp-includes/js/jquery/jquery.js?ver=1.11.1:2:27248)
at fireWith (http://localhost/wp-includes/js/jquery/jquery.js?ver=1.11.1:2:28057)
at ready (http://localhost/wp-includes/js/jquery/jquery.js?ver=1.11.1:2:29901)
at J (http://localhost/wp-includes/js/jquery/jquery.js?ver=1.11.1:2:30261)
> 

问题可能出在您的砌体函数上,而不是小部件本身。默认的 WC 购物车小部件仅为小部件创建一个空的div;然后它使用 JS 插入产品。您显示的砌体JS极有可能导致某种错误,从而阻止WC的JS工作。这就是为什么当您禁用脚本时,小部件工作正常的原因。您需要检查控制台是否存在发现的任何 JS 错误并更正它们。