This is the code which I have written for the custom loop code for the product-archive page. I want to use ajax for adding products to the cart. How should I do it?
I would also like to know which woocommerce function show woocommerce notices to the customer. Like when I click add to cart Notice should be shown to the client that product has been added.
$args = array(
'post_type' => 'product',
'posts_per_page' => 12,
);
$loop = new WP_Query($args);
if ($loop->have_posts()) {
while ($loop->have_posts()): $loop->the_post();
?>
<!-- tab product -->
<li class="col-sx-12 col-sm-4">
<div class="product-container">
<div class="left-block">
<a href="<?php echo get_permalink(); ?>" target="_blank">
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($loop->post->ID), 'single-post-thumbnail');?>
<img height="300px" width="300px" class="img-responsive" alt="product" src="<?php echo $image[0]; ?>">
</a>
<div class="quick-view">
</div>
<div class="add-to-cart ">
<a href="<?php echo $product->add_to_cart_url(); ?>" class="cart">
<span>
<span class="add-to-cart-content">Add To Cart
</span>
</span>
</a>
</div>
</div>
<div class="right-block">
<h5 class="product-name">
<a href="<?php echo get_permalink(); ?>" target="_blank" class="product-block-click">
<?php echo $product->get_title(); ?>
</a>
</h5>
<div class="content_price">
<span class="price product-price">
<i class="fa fa-inr" aria-hidden="true">
</i>
<?php echo $product->get_regular_price(); ?>
</span>
<span class="price old-price">
<i class="fa fa-inr" aria-hidden="true">
</i>
<?php echo $product->get_sale_price(); ?>
</span>
<span class="discount-block">50 % OFF
</span>
</div>
</div>
</div>
</li>
<?php
endwhile;
}
echo "</ul>";
wp_reset_postdata();
?>
