questions

Where I can get the location of wc_get_template_part( ‘content’, ‘product’ )

Rate this post

I have created the custom shop page in wooommerce and I removed all the code from then archive-product.php and added the below code and it’s displaying the products.

defined( 'ABSPATH' ) || exit;

get_header( 'shop' );

/**
 * Hook: woocommerce_before_main_content.
 *
 * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
 * @hooked woocommerce_breadcrumb - 20
 * @hooked WC_Structured_Data::generate_website_data() - 30
 */
do_action( 'woocommerce_before_main_content' );

?>
<div class="container">

<div class="products">
 <div class="row">
    <?php
    
        $args = array(
            'post_type' => 'product',
            'posts_per_page' => 12
            );
        $loop = new WP_Query( $args );
        if ( $loop->have_posts() ) {
            while ( $loop->have_posts() ) : $loop->the_post();
                wc_get_template_part( 'content', 'product' );
            endwhile;
        } else {
            echo __( 'No products found' );
        }
        wp_reset_postdata();
    ?>
</div>
</div>
</div>
<?php

get_footer( 'shop' );

Now Where I will get the code of this wc_get_template_part( 'content', 'product' ); because I have to change the strcture Below screenshot is the woocommerce template.

aa4

 

✔️Solution:

As it’s used inside the product loop, the template file that is called in:

wc_get_template_part( 'content', 'product' );

is content_product.php located in the woocommerce plugin folder > templates subfolder (Take a look to the code on HERE).

Note: you can override WooCommerce templates via your active child theme (or active theme) or use all available hooks in the template content_product.php.


For the displayed thumbnail:

You can see on content_product.php template this:

    /**
     * Hook: woocommerce_before_shop_loop_item_title.
     *
     * @hooked woocommerce_show_product_loop_sale_flash - 10
     * @hooked woocommerce_template_loop_product_thumbnail - 10 // <=== HERE
     */
    do_action( 'woocommerce_before_shop_loop_item_title' );

So Image is called via the template function woocommerce_template_loop_product_thumbnail() and that function call woocommerce_get_product_thumbnail() function:

    /**
     * Get the product thumbnail, or the placeholder if not set.
     *
     * @param string $size (default: 'woocommerce_thumbnail').
     * @param int    $deprecated1 Deprecated since WooCommerce 2.0 (default: 0).
     * @param int    $deprecated2 Deprecated since WooCommerce 2.0 (default: 0).
     * @return string
     */
    function woocommerce_get_product_thumbnail( $size = 'woocommerce_thumbnail', $deprecated1 = 0, $deprecated2 = 0 ) {
        global $product;

        $image_size = apply_filters( 'single_product_archive_thumbnail_size', $size );

        return $product ? $product->get_image( $image_size ) : '';
    }
}

Leave a Reply

Your email address will not be published.

Back to top button