Adding Woocommerce Add to Cart Related Products Button and Product List

I'm having difficulty adding additional products to WooCommerce since I'm still new to this. I am trying to add the "Add to Cart" button to the relevant products and product list.

I looked through the codes and got stuck below.

<a href="<?php the_permalink(); ?>">

        <?php
            /**
             * woocommerce_before_shop_loop_item_title hook
             *
             * @hooked woocommerce_show_product_loop_sale_flash - 10
             * @hooked woocommerce_template_loop_product_thumbnail - 10
             */
            do_action( 'woocommerce_before_shop_loop_item_title' );
        ?>

        <h3><?php the_title(); ?></h3>

        <?php
            /**
             * woocommerce_after_shop_loop_item_title hook
             *
             * @hooked woocommerce_template_loop_price - 10
             */
            do_action( 'woocommerce_after_shop_loop_item_title' );
        ?>

    </a>

    <?php do_action( 'woocommerce_after_shop_loop_item' ); ?>  

Hope someone can guide me on how to add a button. Thanks in advance.

+5
source share
5 answers

To explain that each do_action is inside woocommerce-hooks.php and points to a function inside woocommerce-template.php

Creates a thumbnail:

Function Name: woocommerce_template_loop_product_thumbnail()

do_action( 'woocommerce_before_shop_loop_item_title' );

Provides the price:

Function Name: woocommerce_template_loop_price()

do_action( 'woocommerce_after_shop_loop_item_title' );

Add to Cart Button:

Function Name: woocommerce_template_loop_add_to_cart()

do_action( 'woocommerce_after_shop_loop_item' );
+12
source

woocommerce_template_loop_add_to_cart wordpress.

WooCommerce woocommerce_after_shop_loop_item wp-content\plugins\woocommerce\woocommerce-hooks.php

add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );

, Mystile, 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);

, " ".

+8

" " , :

wp-content/plugins/woocommerce/templates/content-product.php

:

wp-content/themes/myChildTemplate/woocommerce/content-product.php

:

        do_action( 'woocommerce_after_shop_loop_item_title' );
    ?>

</a>

:

        do_action( 'woocommerce_after_shop_loop_item_title' );
    ?>

</a>
    <?php do_action('woocommerce_simple_add_to_cart'); ?>
+4

FYI , , , ...

// Add add to cart button on archive page products
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_add_to_cart', 10 );
+2

Using WooCommerce on Wordpress ElegantTheme (Divi), I added this line to functions.php:

add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_add_to_cart', 10 );

He adds the Add to Cart button immediately after the name and price (for example, the Add to Cart button on the product)

+1
source

All Articles