【问题标题】:Woocommerce display products in html tableWoocommerce 在 html 表格中显示产品
【发布时间】:2015-07-25 07:08:23
【问题描述】:

我正在尝试在普通的 html 表格中显示 WooCommerce 产品列表。这些产品确实是简单的产品;每个都包含一个产品名称、两个自定义字段(质量和尺寸)和一个“添加到报价”按钮。这就是将在前端显示的所有内容。

在 loop-start.php 中,我添加了开头的 <table> 标记。在 loop-end.php 中,我添加了结束 </table> 标记。但是,当加载前端页面并查看源代码时,每个产品都有自己的<table></table> 标签。我只想要一张桌子...

循环启动.php:

<table> <?php echo (function_exists('sometheme_woo_shop_columns_class') ? sometheme_woo_shop_columns_class() : ''); ?>">

循环结束.php:

</table>

内容产品.php:

    <?php do_action( 'woocommerce_before_shop_loop_item' ); ?>

        <?php
            /**
             * woocommerce_before_shop_loop_item_title hook
             *
             * @hooked woocommerce_show_product_loop_sale_flash - 10
             * @hooked woocommerce_template_loop_product_thumbnail - 10
             */
            do_action( 'woocommerce_before_shop_loop_item_title' );
        ?>
<tr>
<td>        <h5><?php the_title(); ?></h5></td>



        <?php
            /**
             * woocommerce_after_shop_loop_item_title hook
             *
             * @hooked woocommerce_template_loop_rating - 5
             * @hooked woocommerce_template_loop_price - 10
             */
            do_action( 'woocommerce_after_shop_loop_item_title' );
        ?>
<td>        <?php echo get_post_meta( get_the_ID(), '_mass_field', true );  ?></td>
<td>        <?php echo get_post_meta( $post->ID, '_dimensions_field', true ); ?></td>
<td>

    <?php

        /**
         * woocommerce_after_shop_loop_item hook
         *
         * @hooked woocommerce_template_loop_add_to_cart - 10
         */
        do_action( 'woocommerce_after_shop_loop_item' ); 

    ?>
</td>
</tr>

前端产品页面来源:

<div class="relative-container">...</div>
<div cass="boxed layout boxed colors</div>
<table>...</table>
<div class="relative-container">...</div>
<div cass="boxed layout boxed colors</div>
<table>...</table>
<div class="relative-container">...</div>
<div cass="boxed layout boxed colors</div>
<table>...</table>
<div class="relative-container">...</div>
<div cass="boxed layout boxed colors</div>
<table>...</table>
etc.

【问题讨论】:

    标签: html woocommerce html-table


    【解决方案1】:

    鉴于我一直在寻找此解决方案一段时间(在发布问题之前),我将在此处发布解决方案以防其他人需要相同的解决方案。

    问题:Wordpress 自动格式化在生成前端时会插入&lt;table&gt;&lt;/table&gt; 标签。因此,解决方案是禁用 Wordpress 自动格式化。将这一行添加到 functions.php 就可以了:

    remove_filter('the_content', 'wpautop'); 
    

    但是,这将全局禁用自动格式化。我只希望它在生成产品页面时发生。一种解决方案是创建一个在商店页面输出之前调用的函数:

    function remove_wp_autoformatting () {
        remove_filter('the_content', 'wpautop');
        }
    
    add_action ('woocommerce_before_shop_loop_item', 'remove_wp_autoformatting');
    

    为了全面披露,我还是个新手。因此,如果有人有更有效的解决方案,将不胜感激。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-02
      • 2017-11-24
      • 1970-01-01
      • 1970-01-01
      • 2019-08-02
      • 1970-01-01
      • 2017-06-14
      相关资源
      最近更新 更多