Woocommerce Cart 小部件不显示任何内容 [英] Woocommerce Cart widget displays no content

查看:35
本文介绍了Woocommerce Cart 小部件不显示任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 woocommerce Cart Widget 添加到我的侧边栏,并且由于主题和 woocommerce 行为的一些自定义,我将这行代码添加到我的主题 functions.php:

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

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

</一边>

如您所见,所有三个产品都显示出来,按钮也出现了.但是,它们并未显示在所有其他页面上.在这些页面上只显示小部件标题.在这些页面上,标记如下所示:

</一边>

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

我发现这与我的自定义有关.当我使用标准的二十十二主题时(在我的子主题上)它工作正常.

编辑

当然,我正在寻找自己并能够进一步缩小范围.原因在于我主题的 function.php 中的这个函数,但我不知道它有什么问题以及我应该怎么做.

函数二十十二岁_儿童砌体(){如果 (!is_admin()) {wp_enqueue_script('砌体');add_action('wp_footer', 'twentytwelve_child_add_masonry');函数二十一点_孩子_添加_砌体(){?><脚本>(函数( $ ) {严格使用";$(函数(){//在var中设置Masonry所在的容器var container = document.querySelector('.products');//创建空的var msnryvar msnry;//在所有图像加载后初始化 Masonry图像加载(容器,函数(){msnry = 新砌体(容器,{itemSelector: '.product',isAnimated: 真});});});}(jQuery));<?php}}}add_action('init', 'twentytwelve_child_masonry');

我正在拔头发..... 我现在正在努力解决这个问题一个星期.请帮忙!?

编辑 2

当我尝试调试项目时收到此消息:

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

解决方案

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

I added the woocommerce Cart Widget to my sidebar and due to some customization of the theme and woocommerce behavior I added this line of code to my themes functions.php:

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

When this line is active no cart contents are shown, just the widget title. When I comment out this line the items in the cart are shown on the single products page and on the shop page. See markup:

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

As you can see all thre products are shown and the buttons appears as well. However they are not shown on all the other pages. On those pages only the widget title appears. on those pages the markup looks like this:

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

The questions I have are: Why is the remove_action line of code interfering with the contents of the cart widget? Why is the div class="widget_shopping_cart_content">empty on the other pages, no matter if the remove_action line is commented out or not.

I figured out that it has something to do with my customization. When I use the standard twentytwelve theme (on wicht my child theme is build) it works fine.

EDIT

Of course I'm searching myself to and was able to narrow it further down. The cause is in this function in my theme's function.php but I don't know what is wrong with it and what I should do about it.

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

I'm pulling my hair out..... I'm trying for a week now to solve this problem. Please help!?

EDIT 2

I got this message when I try to debug the project:

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

解决方案

The problem probably lies with your Masonry function and not the widget itself. The default WC cart widget creates just an empty div for the widget; it then uses JS to insert the products. It's highly likely that the Masonry JS you show is causing some kind of error that's preventing WC's JS from working. This is why when you disable your script the widget works fine. You need to check your console for any JS errors that you're finding and correct them.

这篇关于Woocommerce Cart 小部件不显示任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆