Skip to content

Instantly share code, notes, and snippets.

@santanup789
Created June 18, 2021 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santanup789/374e2b07a8a0a631f70acd256e04e141 to your computer and use it in GitHub Desktop.
Save santanup789/374e2b07a8a0a631f70acd256e04e141 to your computer and use it in GitHub Desktop.
WooCommerce custom product sort by code
<div class="wrapper-dropdown">
<form class="woocommerce-ordering" method="get">
<select name="orderby" class="orderby filter_orderby" aria-label="Shop order">
<?php
$catalog_orderby = apply_filters( 'woocommerce_catalog_orderby', array(
'menu_order' => __( 'Default sorting', 'woocommerce' ),
'popularity' => __( 'Sort by popularity', 'woocommerce' ),
'rating' => __( 'Sort by average rating', 'woocommerce' ),
'date' => __( 'Sort by latest', '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 '<option value="' . $id . '">' . esc_attr( $name ) . '</option>';
?>
</select></form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment