sajjadh47/Woo-Products-Slider-Pro

Order of Products

prosource561 opened this issue · 1 comments

Love this plugin, however, I have a very specific need.

I am trying to sort the order of products by a custom meta field in ASC order.

Are you able to add this into the plugin? Or how can I modify the function below to include $args in your function?

This is the function I wrote for the standard woocommerce [products] shortcode:

function woocommerce_shortcode_products_orderby( $args ) {
$standard_array = array('menu_order','title','date','rand','id');
if( isset( $args['orderby'] ) && !in_array( $args['orderby'], $standard_array ) ) {
$args['meta_key'] = $args['orderby'];
$args['orderby'] = 'meta_value';
}
return $args;
}

add_filter( 'woocommerce_shortcode_products_query', 'woocommerce_shortcode_products_orderby' );

Example of how to add it to shortcode:
[woopspro_products_slider orderby='_custom_meta_field' order='asc']

Thank you for noticing it, please do wait for few days where I will be releasing a new version of the plugin with that features included so that you can sort using custom meta key with order option.