T
T
twentytvvo2021-01-24 20:22:38
WooCommerce
twentytvvo, 2021-01-24 20:22:38

How to display Woocommerce sorting?

How to display the sorting of products in the filter plugin template?
Preferably with the ability to edit the frontend, at least in the div>ul>li loop format.

Doesn't work: Even plugins that display sorting will help. It is also desirable that it would work on ajax.
<?php woocommerce_catalog_ordering() ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twentytvvo, 2021-01-24
@twentytvvo

found the perfect solution for anyone who needs it:

<ul>
<?php
    $catalog_orderby = apply_filters( 'woocommerce_catalog_orderby', array(
     'menu_order' => __( 'Default sorting', 'woocommerce' ),

    'price'      => __( 'Sort by price: low to high', 'woocommerce' ),

    'price-desc' => __( 'Sort by price: high to low', 'woocommerce' )
) );

if ( get_option( 'woocommerce_enable_review_rating' ) == 'no' )
    unset( $catalog_orderby['rating'] );

foreach ( $catalog_orderby as $id => $name )
    echo '<li><a href="' . get_permalink( woocommerce_get_page_id( 'shop' ) ) . '?orderby=' . $id . '" >' . esc_attr( $name ) . '</a></li>';
?>
</ul>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question