Wordpress Tricks

Woocommerce custom shop page wordpress template

Woocommerce custom shop page wordpress template

woocommerce
371Views

Hello to all, welcome to therichpost.com. In this post, I am sharing the code to make Woocommerce custom shop page wordpress template.  Woocommerce is the most popular e-commerce plugin for WordPress.

It is very easy to use and integrate and there are also so many hooks in Woocommerce, which makes woocommerce customization very easy.

Here is the working and tested code to make Woocommerce custom shop page wordpress template and you can add this into any wordpress theme’s template file:
<?php

/* Template Name: Custom Shop */

get_header();

?>
  <section class="clearfix">
    <div class="container">
      <h4>Products</h4>
        <div class="product-gallery">
          <div class="row">
            <?php

              // WP_Query arguments

              $args = array(

              'post_type' => 'product',

              'post_status' => 'publish',

              'posts_per_page' => -1,
              'tax_query'=>array(      // The taxonomy query
              array(
              'taxonomy'  => 'product_cat',

              'terms'     => array(18,19),
              'operator' => 'NOT IN',
              )
              )
              );
              // The Query

              $query = new WP_Query( $args );
              // The Loop

              if ( $query->have_posts() ) {

              while ( $query->have_posts() ) {

              $query->the_post();

              global $product;

              $product = get_product( get_the_ID() ); 

              ?>

              <div class="col-md-3 col-sm-4">

                <div class="product-img">

                   <div class="product-thumb">

                    <a href="<?php echo get_the_permalink(); ?>" class="product-detail">

                      <?php echo get_the_post_thumbnail(); ?>

                    </a>

                  </div>
                  <div class="product-price">

                    <strong>$<?php echo get_post_meta( get_the_ID(), '_regular_price', true); ?></strong>

                    <?php

                    $products_ids_array = array();

                    foreach( WC()->cart->get_cart() as $cart_item ){

                      $products_ids_array[] = $cart_item['product_id'];

                    }

                    if(in_array(get_the_ID(), $products_ids_array)) {

                      echo '<a href="'.site_url().'/cart/">View Cart</a>';

                    } else {

                      echo '<a href="'.$product->add_to_cart_url().'">Add to Cart</a>';

                    }

                    ?>

                  </div>

                  <h6><?php echo get_the_title(); ?></h6>

                </div>

              </div>

              <?php

              }

              } else {

              // no posts found

              }

              // Restore original Post Data

              wp_reset_postdata();
            ?>                                    
        </div>
      </div>
    </div>
  </section>
<?php get_footer(); ?>

 If you have query related to this post or any thing related to wordpress and woocommerce then please comment below or you can also email me.

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

3 Comments

  • //Stock Movement Summary

    // SELECT rip.product_name, rip.barcode, rips.stock_increase as Stock, rips.stock_decrease as deducted,
    // case
    // when rips.stock_decrease = ‘0’ then REPLACE(rish.qunatity_adjusted, ‘+’, ”)
    // else ‘0’
    // end
    // as received,
    // rips.stock_increase*rip.retail_price as end_value
    // FROM `rv_inventory_product_stock` as rips
    // INNER JOIN rv_inventory_products as rip on rip.id = rips.product_id
    // INNER JOIN rv_inventory_stock_history as rish on rish.product_id = rips.product_id
    // GROUP By rips.product_id

    //Stock on hand

    // SELECT rip.product_name, e.firstname as location, rips.stock_increase as stock_on_hand, rip.retail_price as Average_cost, rips.stock_increase * rip.retail_price as total_cost FROM `rv_inventory_product_stock` as rips
    // INNER JOIN rv_inventory_products as rip on rip.id = rips.product_id
    // INNER JOIN employee as e on e.objectId = rip.owner_id

    //stock movement log

    // SELECT ri.invoice_date, ri.ref_no, rsp.product_price, ri.status, rip.product_name, rsp.staff, e.firstname, p.name, rips.stock_increase, rsp.quantity FROM `rv_invoices` as ri
    // INNER JOIN rv_sale_product as rsp on rsp.`ref_no` = ri.`ref_no`
    // INNER JOIN rv_inventory_products as rip on rip.`id` = rsp.`product_id`
    // INNER JOIN employee as e on e.staff_id = rsp.staff
    // INNER JOIN place as p on p.objectId = ri.location_id
    // INNER JOIN rv_inventory_product_stock as rips on rips.product_id = rsp.product_id
    // where ri.status IN(‘Paid’, ‘Unpaid’) and rsp.staff != 0

  • Great post.
    I’d like to say that I’m using free templates for my blog from affiliate-website-templates. I just wanna know your opinion about this site as I don’t have any experience with this.
    Please don’t forget to share your feedback or suggest me any other platform.
    Thanks.

Leave a Reply

Positive SSL