在WooCommerce存档页面的"表格/列表"视图中使用自定义字段显示特定产品



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

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

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

我使用HTML来实现这一点,添加/?添加到购物车=171&variation_id=175&attribute_pa_setting=在添加到购物车中双击,但无法将自定义字段信息传递到购物车和电子邮件。(我知道用HTML传递信息是不可能的)

有人能帮我吗。以下是我想要的屏幕截图:在此处输入图像描述

好的,我自己解决了。我不知道这是不是正确的方法。

这是代码:

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

最新更新