I have a function that adds a new field to order by on WooCommerce. I would like to display the result for products that have the ‘bestseller’ select box checked.
ACF:
function cw_add_postmeta_ordering_args( $args_sort_cw ) {
$cw_orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) :
apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
switch( $cw_orderby_value ) {
case 'bestseller':
$args_sort_cw['orderby'] = 'meta_value';
$args_sort_cw['order'] = 'desc';
$args_sort_cw['meta_key'] = 'bagdes';
$args_sort_cw['meta_value'] = 'bestseller';
break;
}
return $args_sort_cw;
}
Thanks in advance
Regards.
2
Answers
Good concept but it doesn't work for me my friend. I also changed:
Unfortunately, it did not help.
I changed the coed using a
'meta_query'
with the corrected ACF field key ‘badges
‘, and adjusted sorting parameters that have the ‘bestseller
‘ select box checked, hope that helps