Woocommerce shortcode orderby price is not working

I have spend hours yesterday solving my problem but it didn’t work.
I want to sort my product of a specific brand on price (low to high), all other sorting options work fine title, id, etc.. But my self declared $arg regular_price won’t work.

I have added this code to functions.php in my theme map:

Read More
add_filter( 'woocommerce_shortcode_products_query', 'woocommerce_shortcode_products_orderby' );
function woocommerce_shortcode_products_orderby( $args ) 
{  $standard_array = array('menu_order','title','date','rand','id');    
if( isset( $args['orderby'] ) && !in_array( $args['orderby'], $standard_array ) ) 
{  $args['regular_price'] = $args['orderby'];       
   $args['orderby']  = 'meta_value_num'; }  
  return $args;}

And I use this shortcode :

[product_attribute attribute="merk" filter="bait footwear" per_page="80" columns="4" orderby="regular_price" order="asc"]

The result is here:
http://vintagekledingwinkel.nl/aanbiedingen/bait-footwear/

What am i missing?

Related posts

Leave a Reply

1 comment

  1. Try this code:

        add_filter( 'woocommerce_shortcode_products_query', 'woocommerce_shortcode_products_orderby' );
    
        function woocommerce_shortcode_products_orderby( $args ) {
    
            $standard_array = array('menu_order','title','date','rand','id');
    
            if( isset( $args['orderby'] ) && !in_array( $args['orderby'], $standard_array ) ) {
                $args['meta_key'] = $args['orderby'];
                $args['orderby']  = '_regular_price'; 
            }
    
            return $args;
    
        }
    

    And use below short code:

    [product_attribute attribute="merk" filter="bait footwear" per_page="80" columns="4" orderby="_regular_price" order="asc"]
    

    Let me know the output.