我在哪里可以获得 wc_get_template_part( 'content', 'product' ) 的位置

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

我在 wooommerce 中创建了自定义商店页面,然后删除了所有代码 archive-product.php 并添加了以下代码,它显示了产品。

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' );

现在我将从哪里获得这个 wc_get_template_part( 'content', 'product' ); 的代码,因为我必须更改结构 下面的屏幕截图是 woocommerce 模板。

由于在产品循环中使用,调用的模板文件:

wc_get_template_part( 'content', 'product' );

content_product.php 位于 woocommerce 插件文件夹 > 模板子文件夹 (看看 to the code on HERE.

注:你可以override WooCommerce templates via your active child theme (or active theme) or use all available hooks in the template content_product.php.


对于显示的缩略图:

您可以在 content_product.php 模板上看到:

    /**
     * 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' );

所以Image是通过模板函数调用的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 ) : '';
    }
}

相关: