As is always the case with these code snippets, this one comes from a question by a user in the Divi Theme Users group on Facebook.
Leif Ottosson asked about the ‘Add to Cart’ button on the Divi/WooCommerce shop page. When adding the Divi Shop Module to a page via the Page Builder, the list of products on that page does not include an ‘Add to Cart’ button. The idea being that the user should first view the product before adding it to their cart.
Sometimes, however, it may be quicker or better (from a UX perspective) to allow your user to add to their cart, straight from the product list page.
This can be achieved by using the following PHP code snipped, either in the functions.php file of your child theme, or in a plugin.
// register add to cart action function dac_add_cart_button () { add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_add_to_cart', 10 ); } add_action( 'after_setup_theme', 'dac_add_cart_button' );
Replace the ‘dac’ prefix with any prefix of your own and you should now see the ‘Add to Cart’ button underneath the products on any page where you have used the Shop module.
Leave a Reply to JonathanCancel reply