• Resolved patrickpelsma

    (@patrickpelsma)


    Hello,

    I use custom fields to sort products on my website. Sorting works fine when you enter the URL yourself and press enter. However, when you use the default dropdown menu and click on the option, nothing is being sorted.

    You can try it yourself by going to the following URL and you will see 7 results:
    [ redundant link removed ]

    If you then select the sort option “Student Abroad Score low-high”, it will show all 506 results, whereas only 7 should be displayed. Consequently, if you place your cursor in the URL bar and press enter, it will show the 7 results.

    I am curious about what I am doing wrong. As far as I know, everything is updated to the latest version.

    Looking forward to hearing from you.

    Best regards,

    Patrick

    Code:

    
    // Custom Sort
    function cw_add_postmeta_ordering_args( $args_sort_cw ) {
      $cw_orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) :
            apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
      switch( $cw_orderby_value ) {
        case 'student_abroad_high_low':
          $args_sort_cw['orderby'] = 'meta_value_num';
          $args_sort_cw['order'] = 'desc';
          $args_sort_cw['meta_key'] = 'student_abroad_score';
          break;
           case 'student_abroad_low_high':
                $args_sort_cw['orderby'] = 'meta_value_num';
                $args_sort_cw['order'] = 'asc';
                $args_sort_cw['meta_key'] = 'student_abroad_score';
                break;
      }
      return $args_sort_cw;
    }
    add_filter( 'woocommerce_get_catalog_ordering_args', 'cw_add_postmeta_ordering_args' );
    function cw_add_new_postmeta_orderby( $sortby ) {
       $sortby['student_abroad_high_low'] = __( 'Student Abroad Score high-low', 'woocommerce' );
       $sortby['student_abroad_low_high'] = __( 'Student Abroad Score low-high', 'woocommerce' );
       return $sortby;
    }
    add_filter( 'woocommerce_default_catalog_orderby_options', 'cw_add_new_postmeta_orderby' );
    add_filter( 'woocommerce_catalog_orderby', 'cw_add_new_postmeta_orderby' );
    

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Sort button not working’ is closed to new replies.