WPSolr logo
Search
Close this search box.
wpsolr
Keymaster
4 years, 2 months ago #18158

I checked in depth the WooCommerce code, but could not find a way to force the WooCommerce sortby drop down list with a default value. I could not even make work the standard WooCommerce default sortby value (defined in the customizer).

The default sortby is applied by WPSOLR. But it is not displayed as selected in the WooCommerce dropdown list.

In woocommerce_catalog_ordering() of file wc-template-functions.php:
$default_orderby = wc_get_loop_prop( ‘is_search’ ) ? ‘relevance’ : apply_filters( ‘woocommerce_default_catalog_orderby’, get_option( ‘woocommerce_default_catalog_orderby’, ” ) );
$orderby = isset( $_GET[‘orderby’] ) ? wc_clean( wp_unslash( $_GET[‘orderby’] ) ) : $default_orderby; // WPCS: sanitization ok, input var ok, CSRF ok.

The 2 lines above show that the default orderby is always ‘relevance’ for search, unless ‘orderby’ url query parameter is set by a previous user selection.

  • This reply was modified 4 years, 2 months ago by wpsolr.