Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
141 views
in Technique[技术] by (71.8m points)

php - Woocommerce i am not able to show featured products on search page

In storefront theme, for no result in search page, I would like to show featured products in that view.

So in /storefront/woocommerce/loop/no-product-found.php, i've added this code:

<div class="site-main">
  

<?php echo do_shortcode('[products per_page="10" columns="3"]')?>
</div>

So when i search for something like "shoes",I was hoping wordpress to show no results and then goes on showing the featured products. However, I'm not able to show the featured products.

When I check the query, its partly due to the page is in search where there is a query searching for the product name which is "shoes".

Is there a way to exclude that in any queries for search page? If that makes any sense.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The shortcode you tried to use is incorrect.

The shortcode for featured products is:

echo do_shortcode('[featured_products limit="3"]');

Note: you could also pass it a limit.

woocommerce shortcodesDocs


Other related shortcodes:

For products on sale:

echo do_shortcode('[sale_products]');

For popular products:

echo do_shortcode('[best_selling_products]');

For top rated products:

echo do_shortcode('[top_rated_products]');

For recent products:

echo do_shortcode('[recent_products]');

Since you're using storefront theme, it has a 404 page which shows featured products and Popular Products etc. by default! You don't have to change/modify any of its templates. However, if you're overridding storefront with woocommerce templates then you could go ahead and manipulate any template you want using the shortcodes i just gave you!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...