Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order of Products #2

Open
prosource561 opened this issue Sep 21, 2023 · 1 comment
Open

Order of Products #2

prosource561 opened this issue Sep 21, 2023 · 1 comment

Comments

@prosource561
Copy link

prosource561 commented Sep 21, 2023

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']

@sajjadh47
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants