Order By Woocommerce Attributes
-
I have a Year (year-2) and Season (season) Product attribute set up on my product and I would like all my products pages to order by Year + Season. At first, I tried only to order by year but I’m unable to:
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' ); function custom_woocommerce_get_catalog_ordering_args( $args ) { $orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) ); if ( 'year_season' == $orderby_value ) { $args['orderby'] = 'year-2'; $args['meta_key'] = '_product_attributes'; $args['order'] = 'desc'; } return $args; } add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' ); add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' ); function custom_woocommerce_catalog_orderby( $sortby ) { $sortby['year_season'] = 'Sorty By: Year + Season'; return $sortby; }Since _product_attributes is serialized is it even possible to sort by product attributes?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Order By Woocommerce Attributes’ is closed to new replies.