I'm doing a pizza menu on my home page using a custom loop for that, and I want to print the pizza size variations with the prices.
<ul class="products">
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'product_cat' => 'pizza',
);
$my_loop = wc_get_products($args);
foreach ($my_loop as $key => $product)
{
echo '<li>';
echo '<h3>';
echo $product->get_title();
echo '</h3>';
echo '<div>';
echo apply_filters( 'woocommerce_description', $product->post->post_content);
echo '</div>';
if ($product->get_type() == "variable") {
foreach ($product->get_variation_attributes() as $variations)
echo '<pre>'; echo var_dump($variations); echo '</pre>';
{
foreach ($variations as $variation) {
echo '<p>';
if ( $variation = '32-cm') {
echo 'pizza 32 cm - ';
echo $min_regular_price = $product->get_variation_regular_price( 'min' );
}
echo '</p><p>';
if ( $variation = '45-cm') {
echo 'pizza 45 cm - ';
echo $max_regular_price = $product->get_variation_regular_price( 'max' );
}
echo '</p>';
}
}
}
echo '</li>';
}
?>
</ul><!-- .products-->
So my problem with this code is that I'm getting the results twice for every product:
pizza 32 cm - 27.00
pizza 45 cm - 46.00
pizza 32 cm - 27.00
pizza 45 cm - 46.00
can you please point me out on my mistakes with this code?
Aucun commentaire:
Enregistrer un commentaire