T
T
Torvolf2018-03-13 09:28:31
WordPress
Torvolf, 2018-03-13 09:28:31

How to display products using php in woocommerce?

There is such a code

<div class="azera_shop_products_container">
            <?php
            if ( $cat == 'all' ) {
              $args = array( 'post_type' => 'product', 'stock' => 1, 'posts_per_page' => $nb_of_products, 'orderby' => 'date','order' => 'DESC' );
            } else {
              $args = array( 'post_type' => 'product', 'stock' => 1, 'posts_per_page' => $nb_of_products, 'orderby' => 'date','order' => 'DESC', 'product_cat' => $cat );
            }
            $loop = new WP_Query( $args );
            while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>

              <div class="col-md-4 col-sm-6 home-shop-product-wrap-all">

                <div class="home-shop-product-wrap">
                  <div class="home-shop-product-img">
                    <?php
                    if ( has_post_thumbnail( $loop->post->ID ) ) {
                      echo get_the_post_thumbnail( $loop->post->ID,'azera_shop_home_prod' );
                    } else { 											echo '<img src="' . woocommerce_placeholder_img_src() . '" alt="Placeholder" />';
                    }
                    ?>
                  </div>
                  <p class="home-shop-product-price">
                    <?php echo $product->get_price_html(); ?>
                  </p>
                  <div class="home-shop-product-info">
                    <a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                      <div class="home-shop-product-title">
                        <h3><?php the_title(); ?></h3>
                      </div>
                    </a>
                    <div class="home-shop-product-content">
                      <?php the_excerpt(); ?>
                    </div>
                    <div class="home-add-to-cart-wrap">
                      <?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
                    </div>
                  </div>
                </div>
              </div>

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

I can’t understand what needs to be changed here to display products of a certain category?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Drobyshev, 2018-03-13
@antoshadrobyshev

You don't need to change template files. This is done through the woocommerce_product_query hook (in functions.php or in your plugin).
Here is an example of How to Hide Certain WooCommerce Categories in a Store?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question