Hi,
I am trying to sort by price both simple and variable products displayed by a Toolset views using Toolset Woocommerce Blocks.
It just doesn't work and products are randomly sorted.
The code I use for sorting is :
[wpv-filter-start hide="false"]
[wpv-filter-controls]
<div class="form-group">
<label for="product_cat">[wpml-string context="wpv-views"]Catégories de produits[/wpml-string]</label>
[wpv-control-post-taxonomy taxonomy="product_cat" type="select" default_label="Toutes" url_param="product_cat" hide_empty="false"]
</div>
<div class="sort-by">
<label>Trier par :</label>
[wpv-sort-orderby type="select" options="post_title,post_date,field-views_woo_price" label_for_post_title="Titre" label_for_post_date="Date" label_for_field-views_woo_price="Prix" orderby_as_numeric_for="field-views_woo_price" orderby_ascending_for="post_title,post_date,field-views_woo_price"][wpv-sort-order type="select" options="asc,desc" label_for_asc="Par ordre croissant" label_for_desc="Par ordre décroissant" label_asc_for_post_title="A à Z" label_desc_for_post_title="Z à A" label_asc_for_post_date="Le plus ancien" label_desc_for_post_date="Le plus récent" label_asc_for_field-views_woo_price="Le plus bas" label_desc_for_field-views_woo_price="Le plus élevé"]
</div>
<div class="form-group search">
[wpv-filter-search-box placeholder="Rechercher un produit" output="bootstrap"]<span class="icon_close"></span>
</div>
[wpv-filter-spinner spinner="/wp-content/plugins/wp-views/embedded/res/img/ajax-loader3.svg"][/wpv-filter-spinner]
[/wpv-filter-controls]
[wpv-filter-end]
The issue may be viewed here:
versteckter Link ( login = mpc, password = mpc25)
Cheers.
Hi,
Welcome to Toolset support. Would you please double-check if you follow the steps mentioned in the documentation below?
https://toolset.com/documentation/legacy-features/views-plugin/woocommerce-views-calculated-fields-and-batch-update/
If yes, please check if the same issue happens on a minimal installation:
- IMPORTANT STEP! Create a backup of your website. Or better approach will be to test this on a copy/staging version of the website to avoid any disruption of a live website.
- Switch to the default theme such as "TwentyTwenty" by going to "WordPress Dashboard > Appearance > themes".
- Go to "WordPress Dashboard > Plugins" and deactivate all plugins except:
. Toolset Types
. Toolset Views
. Toolset WooCommerce Blocks
. WooCommerce
- Check if you can still recreate the issue.
- If not, re-activate your plugins one by one and check the issue each time to find out the plugin that causes the problem.
If the problem persists, I'd appreciate it if you could give me the URL/User/Pass of your WordPress dashboard after you make sure that you have a backup of your website.
It is absolutely important that you give us a guarantee that you have a backup so if something happens you will have a point of restore.
Make sure you set the next reply as private.
Also tell me which view to check on the dashboard.
Thanks.
Hi,
Thank you for the login information. Your code was:
[wpv-sort-orderby type="select" options="post_title,post_date,field-views_woo_price" label_for_post_title="Nom" label_for_post_date="Date" label_for_field-views_woo_price="Prix" orderby_as_numeric_for="field-views_woo_price" orderby_ascending_for="post_title,post_date,views_woo_price"][wpv-sort-order type="select" options="asc,desc" label_for_asc="Par ordre croissant" label_for_desc="Par ordre décroissant" label_asc_for_post_title="A à Z" label_desc_for_post_title="Z à A" label_asc_for_post_date="Le plus ancien" label_desc_for_post_date="Le plus récent" label_asc_for_field-views_woo_price="Le plus bas" label_desc_for_field-views_woo_price="Le plus élevé"]
I changed it to the default WooCommerce price and it worked:
[wpv-sort-orderby type="select" options="post_title,post_date,price" label_for_post_title="Nom" label_for_post_date="Date" label_for_price="Prix" orderby_as_numeric_for="price" orderby_ascending_for="post_title,post_date,price"][wpv-sort-order type="select" options="asc,desc" label_for_asc="Par ordre croissant" label_for_desc="Par ordre décroissant" label_asc_for_post_title="A à Z" label_desc_for_post_title="Z à A" label_asc_for_post_date="Le plus ancien" label_desc_for_post_date="Le plus récent" label_asc_for_price="Le plus bas" label_desc_for_price="Le plus élevé"]
Thanks.
Hi,
I have already given this a try. It works if you sort products by ascending prices but doesn't work with descending prices.
Cheers.
Hi,
Thank you. I wonder if we have permission to copy the website to our server so we can test and report this to our second-tier support?
Thanks.
Hi,
Yes you are allowed to do that. How would you proceed? By installing the Duplicator plugin?
Cheers.
Hi,
Thanks, yes I installed Duplicator and created a package.
What I saw is that you use a custom shortcode and that shows the lowest price for the Variable products.
But if you use the [wpv-woo-product-price] shortcode (I added to your website and you can check) you will see that the sort order uses the top amount for the prices of variable products.
The [wpv-woo-product-price] shortcode shows the lowest and highest price and you will see that by considering the top price the ordering is working correct.
Thanks.
Hi,
I use the custom [woo_custom_product_price] shortcode because I need to display prices in a custom way ("From..." for variable products).
You are right, sorting by price is OK with [wpv-woo-product-price] shortcode.
Thanks for your insight, you may close the ticket.
Hi,
Any possibility to get variable products minimum price instead of maximum price when ordering products by maximum price?
Hi,
No unfortunately, there is no such option available in the Toolset sorting feature.
Thanks.
Hi,
I finally worked it out by adding the following code in my theme functions.php:
add_filter( 'woocommerce_get_catalog_ordering_args', 'woo_catalog_ordering_args_filter', 10, 3 );
function woo_catalog_ordering_args_filter( $args, $orderby, $order ){
if ( $orderby === 'price' && 'DESC' === $order ) {
add_filter( 'posts_clauses', 'woo_order_by_price_desc_post_clauses', 10, 2 );
}
return $args;
}
function woo_order_by_price_desc_post_clauses( $clauses, $query ) {
global $wpdb;
$clauses['join'] .= " LEFT JOIN {$wpdb->wc_product_meta_lookup} AS price_meta ON {$wpdb->posts}.ID = price_meta.product_id ";
$clauses['orderby'] = " price_meta.min_price DESC, {$wpdb->posts}.ID DESC ";
return $clauses;
}
I hope it will help!