在 WooCommerce 存档页面中使用自定义字段在 Table/List 视图中显示特定产品

Show specific Products in Table/List view with custom field in WooCommerce Archive Page

我有一个普通访客用户的普通商店、类别和单一产品页面。 我想在 table 或列表视图中显示这些产品,其中包含一些普通用户无法使用的自定义字段。他们有自己的自定义字段,我使用 WooCommerce 产品附加组件扩展创建了这些字段。

我尝试使用插件来实现产品 Table 视图,但它们不能满足我的要求。

我想在自定义页面中添加一个自定义文本输入字段和两个数量字段;数量字段将在总数量字段列中汇总,该列将用于乘以变化价格。

我已经使用 HTML 来实现这一点,添加 /?add-to-cart=171&variation_id=175&attribute_pa_setting=Double-Din 进入 ADD TO CART 但无法将自定义字段信息传递到购物车和电子邮件。 (我知道用 HTML 传递信息是不可能的)

谁能帮帮我。 这是我想要的屏幕截图: enter image description here

好的,我自己解决了。 不知道这样对不对。

代码如下:

   <table>

        <thead>
          <tr>
            <th></th>
            <th>Name</th>
            <th>Message Box</th>
            <th>Price</th>                
            <th>Quantity</th>
            <th>Submit</th>
          </tr>
          </thead>

    <tbody class="products-main">
        <?php
            $args = array( 
            'post_type' => 'product', 
            'posts_per_page' => 15, 
            'product_cat' => '', 
            'post__in' => array( 105, 231, 524),
            'orderby' => 'title' );
            $loop = new WP_Query( $args );
            while ( $loop->have_posts() ) : $loop->the_post(); 
            global $product; 
        ?>
        <tr class="product-single">

        <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="cart" method="post" enctype='multipart/form-data'>

            <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">

            <td>
                <?php woocommerce_show_product_sale_flash( $post, $product ); ?>

                <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="300px" height="300px" />'; ?>

            </td>

            <td>
                <h3><?php the_title(); ?></h3>
            </td>

            <td>
                <input type="text" placeholder="Type Your Message" />
            </td>

           <td>
                <span class="price">
                    <?php echo $product->get_price_html(); ?>
                </span>                    
           </td>

            </a>

            <td>
                <?php woocommerce_quantity_input(); ?>
            </td>

            <td>

                <input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->id ); ?>" />

                <button type="submit" class="single_add_to_cart_button button alt">
                    <?php echo esc_html( $product->single_add_to_cart_text() ); ?>
                </button>

            </td>
        </form>
        </tr>

<?php endwhile; ?>
<?php wp_reset_query(); ?>


    </tbody>
</table>