WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Reorder products by SKU (1 post)

  1. GusRuss89
    Member
    Posted 1 year ago #

    I'm trying to get the default product display to be sorted by the sku field in ascending order. So far I've come up with this:

    /* Order products by SKU */
    function reorder_products_by_sku( $query ) {
    	if(is_shop() && ! is_admin() && $query->is_main_query()) {
    		$query->set('orderby', 'meta_value_num');
    		$query->set('meta_key', 'sku');
    		$query->set('order', 'ASC');
    	}
    }
    add_action( 'pre_get_posts', 'reorder_products_by_sku' );

    This just tells me there are no products found which match my selection. Can anyone point me towards what I'm doing wrong?

    Thanks

    http://wordpress.org/extend/plugins/woocommerce/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic