• 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)
  • Plugin Author RazyRx

    (@razyrx)

    Hello,

    Plugin use custom taxonomy for brands.
    Not sure how it must be used, but it seems WordPress do not have such functionality by default and you need to modify SQL query to sort.

    Regards,
    Oleg

    Thread Starter rawald

    (@rawald)

    Any idea on the SQL or even point to the right direction ? Or perhaps the key that im searching such as pa_brands

    Plugin Author RazyRx

    (@razyrx)

    Hello,

    We do not provide support with custom code.

    meta_key can be used only for custom post meta, but our plugin use custom taxonomy functionality.

    Regards,
    Oleg

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Create a sort by in Shop Page’ is closed to new replies.