Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

woocommerce code for cart button

I need to add the woocommerce cart button to one of my pages and was wondering if someone could help with the code required to call the cart button. Here is the current code:

<?php woocommerce_product_loop_start(); ?>

<?php woocommerce_product_subcategories(); ?>

<?php while ( have_posts() ) : the_post(); ?>
<div id="product-image1">
<a href="<?php echo esc_url( get_permalink( $product->id ) ); ?>" title="<?php echo esc_attr( $product->get_title() ); ?>">
  <?php echo $product->get_image(); ?>
</a>
</div>
<div id="product-description-container">
  <ul>
  <a href="<?php echo esc_url( get_permalink( $product->id ) ); ?>" title="<?php echo esc_attr( $product->get_title() ); ?>">
    <li><h4><?php echo $product->get_title(); ?></h4></li></a>
    <li><?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt )?></li>
    <li><h6><?php echo $product->get_price_html(); ?>  **MISSING CODE TO ADD TO CART BUTTON HERE**</h6></li>
 </ul>
</div>
<?php endwhile; // end of the loop. ?>
like image 887
helpanoobout Avatar asked Mar 27 '14 06:03

helpanoobout


People also ask

How do I add a cart shortcode in WooCommerce?

Adding WooCommerce Add to Cart Button Shortcode to Widget Areas. To add the widget, simply navigate to Appearance > Widgets from your WordPress dashboard. Or you can go to the customizer and navigate to Widgets. Drag and drop the Text widget to the area you want to insert in – for instance, the left sidebar.


1 Answers

I think may be you need following code.

Add this code to your place = (**MISSING CODE TO ADD TO CART BUTTON HERE**).

global $product;

echo apply_filters( 'woocommerce_loop_add_to_cart_link',
    sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="button %s product_type_%s">%s</a>',
        esc_url( $product->add_to_cart_url() ),
        esc_attr( $product->get_id() ),
        esc_attr( $product->get_sku() ),
        $product->is_purchasable() ? 'add_to_cart_button' : '',
        esc_attr( $product->get_type() ),
        esc_html( $product->add_to_cart_text() )
    ),
$product );

Hope this will help.

like image 110
Akshay Paghdar Avatar answered Sep 28 '22 12:09

Akshay Paghdar