• I need to retrieve multiple products from woocommerce on my pages (pages that support tags, category etc). So far I succeed to retrive just one product, but now I need to do something more complicated.

    for example:

    I have a page A with tag “x” and “y”, and product in woocommerce B with sku “x” and product C with sku “y” (x and Y the same as the page A). Here’s is my code, code that retrieve me just product of one tag, it dublicate me the result on page.

    <?php
    $posttags = get_the_tags();
    $count=0;
    if ($posttags) {
    foreach($posttags as $tag) {
    $count++;
    if (1 == $count) {
    $args = array( 'post_type' => 'product', 'posts_per_page' => 1,'product_tag' => "' . $tag->slug .'" );
    }
    }
    }
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
    <div style="clear: both;
    width: 100%;
    max-width: 721px;
    margin-bottom: 5px;
    float: left;
    background-color: #D7F1FF;
    border: 1px solid #449BC7;
    padding-top: 4px;
    padding-left: 5px;"><span class="teaser-image-small"><img title="image title" alt="thumb image" class="wp-post-image" src="<?=wp_get_attachment_url( get_post_thumbnail_id() ); ?>" style="width:30px;"></span>
    <span style="
    font-size: 16px;
    vertical-align: 15px;
    ">Cump?r? acum <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> la pre?ul de doar
    <?php echo $product->get_price_html(); ?>
    <!-- <a href="<?php the_permalink(); ?>?add-to-cart=<?php global $post; echo $post->ID; ?>">Cump?r? acum</a> --></span></div>
    <?php endwhile; wp_reset_query(); ?>
    <?php
    $posttags = get_the_tags();
    $count=0;
    if ($posttags) {
      foreach($posttags as $tag) {
        $count++;
        if (2 == $count) {
    $args = array( 'post_type' => 'product', 'posts_per_page' => 1,'product_tag' => "' . $tag->slug .'" );
    }
    }
    }
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
    <div style="clear: both;
    width: 100%;
    max-width: 721px;
    margin-bottom: 5px;
    float: left;
    background-color: #D7F1FF;
    border: 1px solid #449BC7;
    padding-top: 4px;
    padding-left: 5px;"><span class="teaser-image-small"><img title="image title" alt="thumb image" class="wp-post-image" src="<?=wp_get_attachment_url( get_post_thumbnail_id() ); ?>" style="width:30px;"></span>
    <span style="
    font-size: 16px;
    vertical-align: 15px;
    ">Cump?r? acum <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> la pre?ul de doar
    <?php echo $product->get_price_html(); ?>
    <!-- <a href="<?php the_permalink(); ?>?add-to-cart=<?php global $post; echo $post->ID; ?>">Cump?r? acum</a> --></span></div>
    <?php endwhile; wp_reset_query(); ?>

    I need to retrieve first product B if exist in store with sku “x” and second product C if exist with sku “y”. Right now it dublicate me the product. help:D

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Products in page via sku’ is closed to new replies.