Support » Plugin: WP eCommerce » Shortcode sort by SKU

Viewing 6 replies - 1 through 6 (of 6 total)
  • Any ideas on how to sort by sku on the category list?

    Plugin Author Mihai Joldis


    According to the code in the files these are the only parameters that can be passed to sort_order

    // name,dragndrop,price,ID,author,date,title,modified,parent,rand,comment_count

    would you know or have any idea to add the ability to sort by SKU?

    if you’re seriously into code, i have a solution which may be adaptable for your use. You can contact me via the support link on my website, and I’ll send you what i have.


    I resolved this issue. Thank you to Varktech for the code hints.

    I changed the wpsc-list_view.php file to show a list of products, creating table headers.
    Added the code to show the sku in the list:

    <?php echo get_post_meta(wpsc_the_product_id(), '_wpsc_sku', true); ?>

    Added a case to the wpsc-functions.php wpsc_product_sort_order_query_vars around line 826:

    case "sku":
    			add_filter( 'posts_join_sku', 'wpsc_add_meta_table_sku' );
    			add_filter( 'posts_where_sku', 'wpsc_add_meta_table_where_sku' );
    			$query_vars["meta_key"] = '_wpsc_sku';
    			$query_vars["orderby"] = '_wpsc_sku';

    after the function I added the $where and $join statements:

    function wpsc_add_meta_table_where_sku($where){
    	global $wpdb;
    	remove_filter( 'posts_where_sku', 'wpsc_add_meta_table_where_sku' );
    	return $where . ' AND ' . $wpdb->postmeta . '.meta_key = "_wpsc_sku"';
     * add meta table join section for ordering by sku
    function wpsc_add_meta_table_sku($join){
    	global $wpdb;
    	remove_filter( 'posts_join_sku', 'wpsc_add_meta_table_sku' );
    	if(strpos($join, "INNER JOIN ON (".$wpdb->posts.".ID = ".$wpdb->postmeta.".post_id)") !== false){
    		return  ' JOIN ' . $wpdb->postmeta . ' ON ' . $wpdb->posts. '.ID = ' . $wpdb->postmeta . '.post_id';
    		return $join;

    Only reason I posted this is for anyone else that may need to do something similar in the future. I hope it helps, as I could not find or get help other then from varteck.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Shortcode sort by SKU’ is closed to new replies.