use*_*856 1 wordpress wordpress-theming woocommerce hook-woocommerce
我已经在 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' );
Run Code Online (Sandbox Code Playgroud)
现在我将在哪里获得此代码, wc_get_template_part( 'content', 'product' );
因为我必须更改结构下面的屏幕截图是 woocommerce 模板。
由于它在产品循环中使用,因此在以下位置调用模板文件:
wc_get_template_part( 'content', 'product' );
Run Code Online (Sandbox Code Playgroud)
位于content_product.php
woocommerce 插件文件夹 > templates 子文件夹中(查看此处的代码)。
注意:您可以通过活动子主题(或活动主题)覆盖 WooCommerce 模板,或使用模板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' );
Run Code Online (Sandbox Code Playgroud)
因此 Image 是通过模板函数woocommerce_template_loop_product_thumbnail()
和该函数调用woocommerce_get_product_thumbnail()
函数调用的:
/**
* 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 ) : '';
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7290 次 |
最近记录: |