Answer the question
In order to leave comments, you need to log in
How to display a specific Woocommerce product?
I want to display a specific product, that is, these elements
- a picture
- a price
- a description
- a title
I found this code on the Internet
<?php
$loop = new WP_Query( array(
'post_type' => 'product',
'posts_per_page' => 1,
'orderby' => 'menu_order',
'order' => 'ASC',
));
while ( $loop->have_posts() ): $loop->the_post(); ?>
<h2>Product Details</h2>
<div class="col col_13">
<a rel="lightbox[portfolio]" href="<?php the_permalink(); ?>" title="Lady Shoes"><?php the_post_thumbnail("thumbnail-215x300"); ?></a>
</div>
<div class="col col_13 no_margin_right">
<table>
<tr>
<td height="30" width="160">Price:</td>
<td><?php echo $product->get_price_html(); ?></td>
</tr>
<tr>
<td height="30">Availability:</td>
<td>In Stock</td>
</tr>
<tr>
<td height="30">Model:</td>
<td>Product 14</td>
</tr>
<tr>
<td height="30">Manufacturer:</td>
<td>Apple</td>
</tr>
<tr><td height="30">Quantity</td><td><input type="text" value="1" style="width: 20px; text-align: right" /></td></tr>
</table>
<div class="cleaner h20"></div>
<a href="/cart/?add-to-cart=<?php echo $loop->post->ID; ?>" rel="nofollow" data-product-id="<?php echo $loop->post->ID; ?>" class="">Add to cart</a>
<?php ?>
</div>
<div class="cleaner h30"></div>
<h5><strong><?php the_title(); ?></strong></h5>
<p><?php the_content(); ?></p>
<?php endwhile; ?>
Answer the question
In order to leave comments, you need to log in
Probably, the [products] shortcode
by product ID
by product SKU will do.
If you call it in the template code, you will need to wrap it in do_shortcode:
<?php echo do_shortcode('[products ids="ID_ТОВАРА"]'); ?>
<?php echo do_shortcode('[products skus="АРТИКУЛ_ТОВАРА"]'); ?>
so I need to shove woocommerce pieces into specific places of layout. Are there no specialized woocommerce functions? And it turns out it’s necessary for 1 page 1 page in woocommerce, I thought you can make a template and display it there
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question