【问题标题】:Where I can get the location of wc_get_template_part( 'content', 'product' )我在哪里可以获得 wc_get_template_part( 'content', 'product' ) 的位置
【发布时间】:2021-01-20 10:26:00
【问题描述】:

我在 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 模板。

【问题讨论】:

    标签: wordpress woocommerce wordpress-theming hook-woocommerce


    【解决方案1】:

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

    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) 或使用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() 调用的,而该函数调用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 ) : '';
        }
    }
    

    相关: WooCommerce action hooks and overriding templates

    【讨论】:

    • 让我检查一下。给我一些时间
    • 感谢您的帮助,我在 content_product.php 中找到了 li 标签,但您能帮我在哪里获取商店页面上显示的图像和内容吗?
    • 为迟到的回复道歉。是的,它正在工作。从我这边投票。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-19
    • 2011-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多