i am using a custom template for woo-commerce product page, here i display all the product name and product prize. now i want to add woocommerce add-to-cart option with product prize link. Is there a way to make this work? Thanks for your help.
<?php
$args = array( 'post_type' => 'product',
'posts_per_page' => 5,
'post_status' =>'any',
'order' => 'ASC'
);
$allProduct = get_posts( $args );
if ( $allProduct ) {
foreach ( $allProduct as $products ) { ?>
<ul>
<li class="product_name"><a href=""><?php echo apply_filters( 'the_title' , $products->post_title ); ?></li>
<li class="product_prize"><a href="ADD-TO-CART-URL"><span class="pdfIconSmall"> </span></i>Purchase PDF -
<?php $price = get_post_meta( $products->ID, '_regular_price', true);
echo "$ ",$price;
?></a>
</li>
</ul>
<?php
}
} ?>
For a dynamic add to cart you’d need AJAX, but if you just want to show cart (with a widget included) you can add this:
With some js for transitions:
Styling is up to you.
Hope this helps