- What is Astra Pro Add on?
- What Is a Child Theme and How To Install It for Astra?
- How to Activate Astra Pro Addon License?
- How to Get License Key of Astra Pro?
- How to Install Astra Pro Plugin?
- Getting Started with Astra Pro Addon Plugin
- Getting error – The package could not be installed. The theme is missing the style.css stylesheet?
- Do Not See License Activation Form for Astra Pro Addon Plugin?
- How to Install Astra Theme?
- Astra – Customize the Submenu
- The Blank Screen in the Customizer Area
- How to use the color palette of the Astra theme
- How to Import / Export Astra Customizer Settings
- How To Disable Logo Cropping
- How to Create a Sticky Sidebar for Your WooCommerce Shop Page
- How to use dynamic customizer from Astra 4.0.0
- How to Change the Typography of the Astra Menu
- Simplify Your Site Design with the New Style Guide
- How to Translate Astra Theme / Plugins in Your Own Language using GlotPress?
- How to Turn Astra Multilingual with WPML?
- How To Translate Site Builder With WPML?
- How to Translate Astra Strings with WPML?
- How Translations can be Manually Exported and Uploaded to the Site?
- How to Turn Astra Website Multilingual with Polylang?
- How to Translate Categories, Tags, and Astra Strings with Polylang
- How to Turn Astra Website Multilingual with TranslatePress?
- How to translate the WooCommerce string?
- Footer Custom Text Helper Strings
- Does Astra support Beaver Themer Plugin?
- Increasing the PHP Memory Limit of Your Website
- How to Disable Header or Footer for a Landing Page or Post?
- Where Does Astra Primary Color Setting Take Effect?
- How to Adjust the Width of Your Sidebar?
- How to Update the Plugin Manually from WordPress Backend?
- Recommended Settings for Elementor and the Astra Theme
- Recommended Settings for Beaver Builder and the Astra Theme
- How Do License Upgrades Work?
- How to Renew Yearly License?
- How to Apply For Brainstorm Force Affiliate Program? (Become Astra Affiliate)
- How to Manage License on Store?
- How To Update Your Payment Method?
- How do I check my Support Ticket History?
- Frequently Asked Questions – VIP Priority Support
- How to Process Refund Requests?
- Fix Swap Sections Not Working on Mobile (Old Astra Header)
- How to Remove Google Fonts Suggestions in Astra Theme?
- Remove default stretched block layout spacing
- How to Change the Logo on Specific Pages?
- How to remove horizontal & vertical gallery layouts from a single product page?
- Introducing New Filter to Enable/Disable Rank-Math Theme Support
- Enable/Disable YouTube videos from Astra admin dashboard
- How to Fix the Line Height Unit being converted to “EM”?
- How to Change WordPress Post labels to Projects
- Fix for – The PCLZIP_ERR_BAD_FORMAT (-10) Error
- Fix for – Parse error: syntax error, unexpected T_FUNCTION
- How to fix Fatal Error / White Screen of Death?
- Fix for- cURL error 51: SSL: no alternative certificate subject name matches target host name ‘websitedemos.net’
- Getting error – The package could not be installed. The theme is missing the style.css stylesheet?
- ‘The preview could not be loaded’ Pop Up with Astra and Elementor
- Troubleshooting Steps ( with Health Check & Troubleshooting plugin )
- How to Deal with Update Issues in Astra Theme and Astra Pro Addon?
- Blog Featured Image Size Not Working / Error in Image Processing Library
Custom Sorting for Next and Previous Product Navigation
This document provides code snippets to customize the sorting behavior of the next and previous product navigation. By default, products are sorted alphabetically by title. However, you can modify the sorting logic using the astra_woo_product_navigation_sort_args filter.
Default Sorting (Alphabetical by Title)
By default, products are sorted alphabetically by their title in ascending order. No additional code is required for this behavior.
Custom Sorting Snippets
1. Sort by Price (Low to High)
Sort products by price in ascending order (lowest price first).
add_filter( 'astra_woo_product_navigation_sort_args', 'custom_product_sort_by_price_low_to_high' );
function custom_product_sort_by_price_low_to_high( $sort_args ) {
$sort_args['orderby'] = 'meta_value_num'; // Sort by numeric meta value
$sort_args['meta_key'] = '_price'; // Meta key for product price
$sort_args['order'] = 'ASC'; // Sort from low to high
return $sort_args;
}
2. Sort by Price (High to Low)
Sort products by price in descending order (highest price first).
add_filter( 'astra_woo_product_navigation_sort_args', 'custom_product_sort_by_price_high_to_low' );
function custom_product_sort_by_price_high_to_low( $sort_args ) {
$sort_args['orderby'] = 'meta_value_num'; // Sort by numeric meta value
$sort_args['meta_key'] = '_price'; // Meta key for product price
$sort_args['order'] = 'DESC'; // Sort from high to low
return $sort_args;
}
3. Sort by Date (Newest First)
Sort products by date in descending order (newest products first).
add_filter( 'astra_woo_product_navigation_sort_args', 'custom_product_sort_by_date_newest_first' );
function custom_product_sort_by_date_newest_first( $sort_args ) {
$sort_args['orderby'] = 'date'; // Sort by date
$sort_args['order'] = 'DESC'; // Newest first
return $sort_args;
}
4. Sort by Date (Oldest First)
Sort products by date in ascending order (oldest products first).
add_filter( 'astra_woo_product_navigation_sort_args', 'custom_product_sort_by_date_oldest_first' );
function custom_product_sort_by_date_oldest_first( $sort_args ) {
$sort_args['orderby'] = 'date'; // Sort by date
$sort_args['order'] = 'ASC'; // Oldest first
return $sort_args;
}
5. Sort by Popularity (Best-Selling First)
Sort products by popularity (best-selling products first).
add_filter( 'astra_woo_product_navigation_sort_args', 'custom_product_sort_by_popularity' );
function custom_product_sort_by_popularity( $sort_args ) {
$sort_args['orderby'] = 'meta_value_num'; // Sort by numeric meta value
$sort_args['meta_key'] = 'total_sales'; // Meta key for total sales
$sort_args['order'] = 'DESC'; // Best-selling first
return $sort_args;
}
6. Sort by Rating (Highest Rated First)
Sort products by average rating in descending order (highest rated products first).
add_filter( 'astra_woo_product_navigation_sort_args', 'custom_product_sort_by_rating' );
function custom_product_sort_by_rating( $sort_args ) {
$sort_args['orderby'] = 'meta_value_num'; // Sort by numeric meta value
$sort_args['meta_key'] = '_wc_average_rating'; // Meta key for average rating
$sort_args['order'] = 'DESC'; // Highest rated first
return $sort_args;
}
7. Sort by Custom Meta Field
Sort products by a custom meta field (e.g., `_custom_meta_key`).
add_filter( 'astra_woo_product_navigation_sort_args', 'custom_product_sort_by_custom_meta' );
function custom_product_sort_by_custom_meta( $sort_args ) {
$sort_args['orderby'] = 'meta_value'; // Sort by meta value
$sort_args['meta_key'] = '_custom_meta_key'; // Replace with your custom meta key
$sort_args['order'] = 'ASC'; // Sort in ascending order
return $sort_args;
}
8. Sort Randomly
Sort products randomly.
add_filter( 'astra_woo_product_navigation_sort_args', 'custom_product_sort_randomly' );
function custom_product_sort_randomly( $sort_args ) {
$sort_args['orderby'] = 'rand'; // Sort randomly
return $sort_args;
}
How to Use These Snippets
1. Copy the desired snippet.
2. Paste it into your theme’s `functions.php` file or a custom plugin.
3. Save the file and test the changes on your site.
Example: Sorting by Price (Low to High)
add_filter( 'astra_woo_product_navigation_sort_args', 'custom_product_sort_by_price_low_to_high' );
function custom_product_sort_by_price_low_to_high( $sort_args ) {
$sort_args['orderby'] = 'meta_value_num'; // Sort by numeric meta value
$sort_args['meta_key'] = '_price'; // Meta key for product price
$sort_args['order'] = 'ASC'; // Sort from low to high
return $sort_args;
}
Notes
– Customization: You can combine multiple sorting criteria (e.g., sort by price and then by title) by modifying the `orderby` parameter.
We don't respond to the article feedback, we use it to improve our support content.