• Resolved Andrew Schultz

    (@tabboy)


    I have written some code to add a custom sort order by meta value to the shop page. The data to sort by is a member product price, it displays the products with member prices by it does not sort by the value.

    Here is the code

    add_filter('woocommerce_get_catalog_ordering_args', 'es_add_catalog_order_args_member_price');
    
    function es_add_catalog_order_args_member_price($args) {
    
    	if(isset( $_GET['orderby'] )) {
    		$orderby_value = woocommerce_clean( $_GET['orderby'] );
    	}
    
    	if($orderby_value == 'member_price') {
    		$args['meta_key'] = 'member_price';
    		$args['order'] = 'ASC';
    		$args['order_by'] = 'meta_value_num';
    	}
    
    	return $args;
    }

    Cheers!

    https://ww.wp.xz.cn/plugins/woocommerce/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    Are you certain member_price is the meta key and not _member_price? Check your postmeta table in the database.

    Plugin Contributor Mike Jolley

    (@mikejolley)

    And ‘order_by’ is wrong. It should be ‘orderby’.

    Thread Starter Andrew Schultz

    (@tabboy)

    SUCCESS!!! Every article I read on the internet used ‘order_by’ when it should be ‘orderby’. Thanks very much I would kiss you if you were in close proximity 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Custom Sorting By Numeric Meta Value’ is closed to new replies.