FacetWP sorteeropties aanpassen in WooCommerce

Voeg de onderstaande code toe aan de functions.php van je child-theme of maak gebruik van een plugin als bijvoorbeeld code-snippets.

// change facetwp sort by options
add_filter( 'facetwp_sort_options', function( $options, $params ) {
unset( $options['date_asc'] );
unset( $options['title_asc'] );
unset( $options['title_desc'] );
unset( $options['date_desc'] );
$options['default']['label'] = 'Populariteit';

$options['price_asc'] = [
'label' => 'Prijs laag - hoog',
'query_args' => [
'orderby' => 'meta_value_num',
'meta_key' => '_price',
'order' => 'ASC',
]
];
$options['price_desc'] = [
'label' => 'Prijs hoog - laag',
'query_args' => [
'orderby' => 'meta_value_num',
'meta_key' => '_price',
'order' => 'DESC',
]
];

$options['popularity_new'] = [
'label' => 'Populariteit',
'query_args' => [
'orderby' => 'post_views',
'order' => 'DESC',
]
];

return$options;
}, 10, 2 );