Woocommerce随机追加销售
Woocommerce 是否有任何方法可以显示同一产品类别内的随机追加销售产品,而不是为每个产品手动添加追加销售Woocommerce随机追加销售,woocommerce,Woocommerce,Woocommerce 是否有任何方法可以显示同一产品类别内的随机追加销售产品,而不是为每个产品手动添加追加销售 非常感谢…只需修改模板/woocommerce/single product/up-sells.php即可 $cats = get_the_terms($product->id, 'product_cat'); if (!count($cats)) { return; } $args = array( 'post_type' => 'p
非常感谢…只需修改模板/woocommerce/single product/up-sells.php即可
$cats = get_the_terms($product->id, 'product_cat');
if (!count($cats)) {
return;
}
$args = array(
'post_type' => 'product',
'ignore_sticky_posts' => 1,
'no_found_rows' => 1,
'posts_per_page' => $posts_per_page,
'orderby' => 'rand',
'post__not_in' => array( $product->id ),
'meta_query' => $meta_query,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $cats->term_id
)
)
);
$products = new WP_Query( $args );
嘿,我遇到了一个线程,试图找出如何做类似的事情。我使用@ViszinisA提供的大部分查询来tweek up-sells.php模板 up sells.php从第23行开始:
$cats = get_the_terms($product->id, 'product_cat');
if (!count($cats)) {
return;
}
$args = array(
'post_type' => 'product',
'ignore_sticky_posts' => 1,
'no_found_rows' => 1,
'posts_per_page' => 5,
'orderby' => 'rand',
'post__not_in' => array( $product->id ),
'meta_query' => $meta_query,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $cats[0]->term_id
)
)
);
$prodQuery = new WP_Query( $args );
if ( $prodQuery->have_posts() ) {
$postProds = $prodQuery->posts;
?>
<section class="up-sells upsells products">
<h2><?php esc_html_e( 'You may also like…', 'woocommerce' ) ?></h2>
<br>
<?php woocommerce_product_loop_start(); ?>
<?php foreach ( $postProds as $postProd ) : ?>
<?php
// $post_object = get_post( $upsell->get_id() );
setup_postdata( $GLOBALS['post'] =& $postProd );
wc_get_template_part( 'content', 'product' ); ?>
<?php endforeach; ?>
<?php woocommerce_product_loop_end(); ?>
</section>
<?php
}
$cats=get_the_terms($product->id,'product_cat');
如果(!计数($cats)){
返回;
}
$args=数组(
“post_类型”=>“产品”,
“忽略粘性帖子”=>1,
“未找到行”=>1,
“每页帖子数”=>5,
'orderby'=>'rand',
'post__not_in'=>数组($product->id),
“meta\u query”=>$meta\u query,
“tax_query”=>数组(
排列(
“分类法”=>“产品分类”,
“字段”=>“id”,
'terms'=>$cats[0]->term\u id
)
)
);
$prodQuery=新的WP\U查询($args);
如果($prodQuery->have_posts()){
$postProds=$prodQuery->posts;
?>
嗨…你有没有可能发布整个页面?因为我已经用已经存在的内容替换了这个页面,它没有显示任何内容。如果你替换插件文件夹中的原始模板,那么它是错误的。你应该在你的主题中复制它们并在那里编辑它们。这里是原始内容:只替换明显的部分。不显示任何内容从产品中…即使我手动添加一些追加销售也不行。将模板的代码粘贴到pastebin或smth中并共享。如果产品没有追加销售,则退出脚本。您的产品有追加销售吗?天哪。删除第14行和第16行。