Create a sort by in Shop Page
-
Hi there, im trying to create a sort by from the brands plugin to sort in the WooCommerce shop page by alphabetical so All’s then Ben’s etc. I tried using the code below but I dont think I’m accessing your attribute correctly is you could help.
function theme_catalog_orderby( $catalog_orderby_options ) { $catalog_orderby_options['brands'] = __( 'Sort by brands', 'textdomain' ); return $catalog_orderby_options; } add_filter( 'woocommerce_catalog_orderby', 'theme_catalog_orderby' ); /** * Returns an array of arguments for ordering products based on the selected values. * * @uses woocommerce_get_catalog_ordering_args hook * @return array */ function theme_get_catalog_ordering_args( $args ) { $orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) ); if ( 'sale' == $orderby_value ) { $args['meta_key'] = '_product_attribute[pa_brands]'; $args['orderby'] = 'title'; $args['order'] = 'ASC'; } return $args; } add_filter( 'woocommerce_get_catalog_ordering_args', 'theme_get_catalog_ordering_args' );
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Create a sort by in Shop Page’ is closed to new replies.