sort by stock
-
hi, im developer by a client and he wants to develop by stock products
hes using this plugings:
*woocommerce
*WOOF – WooCommerce Products Filter
and a bunch more
im using this piece of code to try to implement this but it dosent return me anythingadd_filter( 'woocommerce_catalog_orderby', 'misha_add_custom_sorting_options' ); function misha_add_custom_sorting_options( $options ){ // $options['title'] = 'Sort alphabetically'; $options['availability'] = 'Ordenar por Cantidad'; return $options; } add_filter( 'woocommerce_get_catalog_ordering_args', 'misha_custom_product_sorting' ); function misha_custom_product_sorting( $args ) { // Sort alphabetically if ( isset( $_GET['orderby'] ) && 'title' === $_GET['orderby'] ) { $args['orderby'] = 'title'; $args['order'] = 'asc'; } // Show products in stock first if( isset( $_GET['orderby'] ) && 'availability' === $_GET['orderby'] ) { $args['meta_key'] = '_stock'; $args['orderby'] = array( 'meta_value' => 'DESC' ); } return $args; }
also this one
add_filter( 'woocommerce_catalog_orderby', 'misha_add_custom_sorting_options' ); function misha_add_custom_sorting_options( $options ){ // $options['title'] = 'Sort alphabetically'; $options['availability'] = 'Ordenar por Cantidad'; return $options; } add_filter( 'woocommerce_get_catalog_ordering_args', 'misha_custom_product_sorting' ); function misha_custom_product_sorting( $args ) { // Sort alphabetically if ( isset( $_GET['orderby'] ) && 'title' === $_GET['orderby'] ) { $args['orderby'] = 'title'; $args['order'] = 'asc'; } // Show products in stock first if( isset( $_GET['orderby'] ) && 'availability' === $_GET['orderby'] ) { echo "entre a orden"; $args['orderby'] = 'meta_value'; $args['order'] = 'DESC'; $args['meta_key'] = '_stock'; } return $args; }
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘sort by stock’ is closed to new replies.