Tuesday 10 June 2014

Woocommerce: Add an ‘add to cart’ button to related products and product listing Woocommerce


  • http://docs.woothemes.com/document/hooks/
I use the Mystile WooCommerce theme, where the "add to cart" buttons is removed by this code:
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
That is placed in this file wp-content/themes/mystile/includes/theme-woocommerce.php
I know I can just remove the piece of code, but is there a option, so the buttons still will appear, after the theme-woocommerce.php file is changed after next update?
I already tried to add this code to the my functions.php in my child theme.
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
Add an ‘add to cart’ button to related products and product listing Woocommerce

I took the mystile WooCommerce theme plus WooCommerce itself for a test drive recently. It is clean and neatly laid out and importantly it is responsive. It allows customers to have the convenience of shopping on their mobile devices without fuss.
I wanted to have the add to cart to show on my featured products page and also on my shop page (where all products are listed). Note that these hooks are already in their respective files.
I got the answer from a contributor on Stackoverflow by the name of Azmi Kamis.
The mystile theme by default does the following:
By default WooCommerce hooks it to woocommerce_after_shop_loop_item in
wp-content\plugins\woocommerce\woocommerce-hooks.php
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
My installed theme, Mystile, removed this hook in wp-content\themes\mystile\includes\theme-woocommerce.php
// Remove add to cart button on archives
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
Once I commented it out, the “Add to cart” button appeared.
He commented out by simply doing this:
// Remove add to cart button on archives
//remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);

1 comment:

  1. Thank you for sharing excellent information. Your website is very cool. Fully useful your blog post... Online shopping site for women's clothing in india

    ReplyDelete