最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Display sorting options dropdown when using WooCommerce product category shortcode

programmeradmin3浏览0评论

I have a WordPress site, with WooCommerce. The WooCommerce archives pages as shop display a dropdown sorting filter like in this screenshot:

Now in another page let's say example/foo On that page I use a WooCommerce shortcode:

[product_category per_page="90" columns="3" orderby="" order="ASC" category="foo" prdctfltr="yes" pagination="yes"]

But the sorting dropdown is not shown.

What I am doing wrong? How can I display the sorting dropdown?

I have a WordPress site, with WooCommerce. The WooCommerce archives pages as shop display a dropdown sorting filter like in this screenshot:

Now in another page let's say example/foo On that page I use a WooCommerce shortcode:

[product_category per_page="90" columns="3" orderby="" order="ASC" category="foo" prdctfltr="yes" pagination="yes"]

But the sorting dropdown is not shown.

What I am doing wrong? How can I display the sorting dropdown?

Share Improve this question edited May 6, 2019 at 23:46 LoicTheAztec 3,39117 silver badges24 bronze badges asked May 6, 2019 at 20:56 TheGejrTheGejr 331 gold badge1 silver badge4 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 4

Since WooCommerce 3.2, Woocommerce shortcodes and their available attributes have changed.

So try the following shortcode instead (for "foo" product category):

[product_category limit="90" columns="3" category="foo" paginate="true"]

or inside php code:

echo do_shortcode( '[product_category limit="90" columns="3" category="foo" paginate="true"]' );

Now you will see that the sorting options dropdown appear.

Note: orderby argument with an empty value has no effect. order argument is ASC by default.

If you would rather want to get the sorting menu using a shortcode then you can create one for it in your functions.php

// Creating Shortcode for Product Sorting
add_shortcode('wc_sorting','woocommerce_catalog_ordering');

Then simply call the shortcode in your catalog page:-

  • In Legacy Editor/Gutenberg: [wc_sorting]
  • or in your PHP file: echo do_shortcode('[wc_sorting]');
发布评论

评论列表(0)

  1. 暂无评论