• Resolved karpovets

    (@karpovets)


    Hello,
    I want to make a second sorting option by_stock.
    I do like this, it does not work(

    function sv_change_sorting_fallback( $fallback, $orderby ) {
        if ( 'featured_first' === $orderby ) {
            $fallback = 'by_stock';
        }
        return $fallback;
    }
    add_filter( 'wc_extra_sorting_options_fallback', 'sv_change_sorting_fallback', 10, 2 );
    function sv_change_sorting_fallback_order( $fallback_order, $orderby ) {
        if ( 'featured_first' === $orderby ) {
            $fallback_order = 'DESC';
        }
        return $fallback_order;
    }
    add_filter( 'wc_extra_sorting_options_fallback_order', 'sv_change_sorting_fallback_order', 10, 2 );

    Help me please!)

    https://ww.wp.xz.cn/plugins/woocommerce-extra-product-sorting-options/

Viewing 1 replies (of 1 total)
  • Plugin Author Beka Rice

    (@bekarice)

    Hey @karpovets, the reason this isn’t working is because stock is measured differently than featured status. The “Featured” meta is sorted by meta_value, while in order for stock to appear numerically, you’d need to sort by meta_value_num.

    Since we’re using what WooCommerce gives us with the sorting options, we can’t do a custom query here to let you sort by two different value types, as we can’t use the meta_type in the sort orderby.

    I’m afraid there’s not really anything we can do here given the filters used in WooCommerce to add sorting arguments to make this work. Sorry I don’t have better news!

Viewing 1 replies (of 1 total)

The topic ‘by_stock – a second sorting parameter’ is closed to new replies.