1
votes

I am using woocommerce to develop a ecommerce site

In single-product.php I am facing a problem.

I can't display the add to cart button under the product in this page.

So far I am using this code:

 <?php 
    //global $post;
    echo do_shortcode('[add_to_cart id="$post->ID"]');
    ?> 

But no luck for me yet!

3
Why are you using shortcode for that? There are built in templates and hooks for that. - ViszinisA
ViszinisA, yes you are right but I am changing the design of the template.. Thats why! - user3257003
then use woocommerce templates and follow guidelines as how to create design for woocommerce. Try reading docs.woothemes.com/document/template-structure and related things described there. - ViszinisA

3 Answers

5
votes

Maybe you made a simple writing mistake? Try this:

<?php 
echo do_shortcode('[add_to_cart id="'.$post->ID.'"]');
?> 
4
votes

I would suggest using the WooCommerce default content-single-product.php template.

By default, the single product's add to cart template is added via the woocommerce_template_single_add_to_cart() function and is added to the woocommerce_single_product_summary hook (priority 30).

If you must change the single product content very radically, you can either call woocommerce_template_single_add_to_cart() directly or add it to a different hook. There's no reason to use a shortcode here.

0
votes

If I understood you right, you want to move the Add-to-Cart button from the top of the page to the bottom of the page, so that it would go below the main product description.

Here is how I've done this on my website:

/* Removing the Add-To-Cart button from right below the product summary.
 */
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );

/* Adding the Add-To-Cart button so that it would go after the main product description.
 */
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_single_add_to_cart', 12 );