PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Custom Ordering by meta_value seems not compatible with WOOF + Ajax

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hello, we are using the premium Version of WOOF for our Onlineshop. I'm trying to add a new sorting option to the shop that sorts by a numeric custom meta_value (product_visit_count). Sorting at first works fine, but as soon as any ajax filtering is triggered WOOF defaults back to sorting by product name alphabetical.

This is the site: https://galerievoigt.de/produkt-kategorie/uhren/

The Default Sorting in WooCommerce is the newly added sorting order"Nach Beliebtheit (V)".

With the attached link, this product should be the first one: https://imgur.com/ZTtcE73

 

After changing any WOOF Filter the sorting seems to break.

This is the code that generates the sorting:

Spoiler
<?php

function skyverge_add_postmeta_ordering_args( $sort_args ) {
$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
switch( $orderby_value ) {
case 'visits':
$sort_args['orderby'] = 'meta_value_num';
$sort_args['order'] = 'desc';
$sort_args['meta_key'] = 'product_visit_count';
break;
}
return $sort_args;
}
add_filter( 'woocommerce_get_catalog_ordering_args', 'skyverge_add_postmeta_ordering_args' );

// Add these new sorting arguments to the sortby options on the frontend
function skyverge_add_new_postmeta_orderby( $sortby ) {

$sortby['visits'] = __( 'Nach Beliebtheit (V)', 'woocommerce' );
return $sortby;
}
add_filter( 'woocommerce_default_catalog_orderby_options', 'skyverge_add_new_postmeta_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'skyverge_add_new_postmeta_orderby' );

?>

Thank you for your help!

Added Envato Order ID

Hello Tobias

To get  license  key - https://codecanyon.net/downloads -> https://c2n.me/49ZXJv0.png

Paste your license key here - https://share.pluginus.net/image/i20210618130558.png -> https://share.pluginus.net/image/i20210618130614.png

Please  update  the  plugin to latest  version - https://products-filter.com/how-to-make-auto-update-for-wordpress-plugins-and-themes-bought-on-envato

Please use this  hook - woof_order_catalog -  https://products-filter.com/woof_order_catalog

OR    this  hook  to  add  order  data - woof_products_query

Hi Pablo,

I've added the key to the private data.

I'll try the hook next and give you feedback. Thank you very much!

Could you give me an example how to hook into the function?

An example:

add_filter('woof_order_catalog', function( $sort_args){

$sort_args['orderby'] = 'meta_value_num';
$sort_args['order'] = 'desc';
$sort_args['meta_key'] = 'product_visit_count';

return  $sort_args;

},10);

 

Worked, thank you very much!

Welcome;)