Created
June 18, 2021 11:21
-
-
Save santanup789/374e2b07a8a0a631f70acd256e04e141 to your computer and use it in GitHub Desktop.
WooCommerce custom product sort by code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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