WP eCommerce
[resolved] Shortcode sort by SKU (7 posts)

  1. jmessick9
    Posted 2 years ago #

    I have a client that needs to have the category shortcode sort the products by sku. Here is the shortcode that I would like to use. Any idea on how I can do this?

    [wpsc_products category_url_name='pir-zia-inayat-khan-recordings' sort_order='product_sku']


  2. jmessick9
    Posted 2 years ago #

    Any ideas on how to sort by sku on the category list?

  3. Mihai
    Plugin Author

    Posted 2 years ago #

    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

  4. jmessick9
    Posted 2 years ago #

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

  5. vark
    Posted 2 years ago #

    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.

  6. jmessick9
    Posted 2 years ago #


  7. jmessick9
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic