我正在寻找帮助(谢谢)编辑Woocommerce php小部件的“特色产品”。
我认为我需要编辑的文件是:
wp-content/plugins/woocommerce/classes/widgets/class-wc-widget-featured-products.php问题是:
所需编辑:
下面是一个例子:
我有三个类别(狗食,猫食,其他东西)。
每个类别都有一个类别主页:
Www.mysite.com/狗食
www.mysite.com/catfood
Www.mysite.com/其他-内容
当我将一个特色产品添加到“狗粮”类别时,这个特色产品小部件也包括特色猫粮产品。如果顾客没有猫,那就没用了。
我希望特色产品小部件只显示当前类别的产品,因此狗粮消费者只会看到狗粮特色产品(不包括猫食或其他东西)。
我(认为)我需要在上面提到的PHP文件中添加一个论证。下面是在文件中找到的当前代码:
$query_args['meta_query'][] = array(
'key' => '_featured',
'value' => 'yes'
);我试着补充:
$query_args['meta_query'][] = array(
'key' => '_featured',
'value' => 'yes',
'product_cat' => 'current_category'
);但这不起作用。
发布于 2014-05-22 04:51:33
使用这个wordpress插件
https://wordpress.org/plugins/sp-woocommerce-featured-product-by-category/
在这个插件中,我们刚刚更改了特色产品的短代码。
默认的短代码是: featured_products per_page="12“columns="4”
在功能产品分类插件的帮助下,这个短代码的修改是: featured_product_categories cats="CATEGORY_ID“per_cat="6”columns="3“
发布于 2014-12-03 18:33:54
我不确定是否要编辑这个小部件,但是我已经成功地将它放在了存档产品模板中,使用如下所示:
<?php
$term = get_queried_object();
$category_id = empty( $term->term_id ) ? 0 : $term->term_id;
$args = array(
'post_type' => 'product',
'meta_key' => '_featured',
'meta_value' => 'yes',
'posts_per_page' => 3,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $category_id
)
)
);
$featured_query = new WP_Query( $args );
if ($featured_query->have_posts()) :
while ($featured_query->have_posts()) :
$featured_query->the_post();
$product = get_product( $featured_query->post->ID );
wc_get_template_part( 'content', 'product' );
endwhile;
endif;
wp_reset_query();
?>发布于 2020-07-06 08:03:35
这已经很晚了,但由于woocommerce不断更新,他们现在引入了wc_get_products作为获取产品的标准方式。
下面是我在我的网站上记录的代码。https://jameshwartlopez.com/plugin/get-featured-products-of-a-category/
<?php
// Display featured products by category. on this case its "shirts" which is the slug of the category.
$query_args = array(
'featured' => true,
'category' => array( 'shirts' ),
);
$products = wc_get_products( $query_args );
global $post;
?>
<div class="woocommerce columns-<?php echo esc_attr( $columns ); ?>">
<?php
woocommerce_product_loop_start();
foreach ($products as $product) {
$post = get_post($product->get_id());
setup_postdata($post);
wc_get_template_part('content', 'product');
}
wp_reset_postdata();
woocommerce_product_loop_end();
?>
</div>https://stackoverflow.com/questions/18743502
复制相似问题