Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Sorting Products by Custom Meta Fields

add_filter( 'woocommerce_shortcode_products_query', 'woocommerce_shortcode_products_orderby' );

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_num'; 
    }

    return $args;
}
Source by woocommerce.com #
 
PREVIOUS NEXT
Tagged: #Sorting #Products #Custom #Meta #Fields
ADD COMMENT
Topic
Name
9+4 =