<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Support Forum - Topic: Sort products by SKU</title>
		<link>http://www.kriesi.at/support/topic/sort-products-by-sku</link>
		<description>Support Forum - Topic: Sort products by SKU</description>
		<language>en-US</language>
		<pubDate>Wed, 19 Jun 2013 10:16:34 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://www.kriesi.at/support/search.php</link>
		</textInput>
		<atom:link href="http://www.kriesi.at/support/rss/topic/sort-products-by-sku" rel="self" type="application/rss+xml" />

		<item>
			<title>Dude on "Sort products by SKU"</title>
			<link>http://www.kriesi.at/support/topic/sort-products-by-sku#post-92018</link>
			<pubDate>Thu, 17 Jan 2013 08:22:31 +0000</pubDate>
			<dc:creator>Dude</dc:creator>
			<guid isPermaLink="false">92018@http://www.kriesi.at/support/</guid>
			<description>&#60;p&#62;1) My php code linter doesn't show any errors - the code syntax itself seems to be correct. Not sure if it really works though. It probably won't work with WC2.0 because it uses a SESSION variable at the top and afaik they switch from sessions to a cookie/transient based system with WC2.0). However it should work with WC1.6.x.&#60;/p&#62;
&#60;p&#62;2) Yes just use the sku option field on the product editor page.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ykblue on "Sort products by SKU"</title>
			<link>http://www.kriesi.at/support/topic/sort-products-by-sku#post-91945</link>
			<pubDate>Wed, 16 Jan 2013 22:17:19 +0000</pubDate>
			<dc:creator>ykblue</dc:creator>
			<guid isPermaLink="false">91945@http://www.kriesi.at/support/</guid>
			<description>&#60;p&#62;Hi, I'm still working on the topic &#34;sort by sku&#34;&#60;br /&#62;
If I edit a product (grouped - quick edit) there is the field SKU. After studying forums in woothemes and other sources, I come out with a code like this&#60;/p&#62;
&#60;p&#62;===============================================&#60;br /&#62;
/**&#60;br /&#62;
* This code should be added to functions.php of your theme&#60;br /&#62;
**/&#60;/p&#62;
&#60;p&#62;add_filter('woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args');&#60;/p&#62;
&#60;p&#62;function custom_woocommerce_get_catalog_ordering_args( $args ) {&#60;br /&#62;
    if (isset($_SESSION['orderby'])) {&#60;br /&#62;
        switch ($_SESSION['orderby']) :&#60;br /&#62;
            case 'date_asc' :&#60;br /&#62;
                $args['orderby'] = 'date';&#60;br /&#62;
                $args['order'] = 'asc';&#60;br /&#62;
                $args['meta_key'] = '';&#60;br /&#62;
            break;&#60;br /&#62;
            case 'price_desc' :&#60;br /&#62;
                $args['orderby'] = 'meta_value_num';&#60;br /&#62;
                $args['order'] = 'desc';&#60;br /&#62;
                $args['meta_key'] = '_price';&#60;br /&#62;
            break;&#60;br /&#62;
            case 'title_desc' :&#60;br /&#62;
                $args['orderby'] = 'title';&#60;br /&#62;
                $args['order'] = 'desc';&#60;br /&#62;
                $args['meta_key'] = '';&#60;br /&#62;
            break;&#60;br /&#62;
            case 'price_desc' :&#60;br /&#62;
                $args['orderby'] = 'meta_value_num';&#60;br /&#62;
                $args['order'] = 'asc';&#60;br /&#62;
                $args['meta_key'] = '_sku';&#60;br /&#62;
            break;&#60;br /&#62;
        endswitch;&#60;br /&#62;
    }&#60;br /&#62;
    return $args;&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;add_filter('woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby');&#60;/p&#62;
&#60;p&#62;function custom_woocommerce_catalog_orderby( $sortby ) {&#60;br /&#62;
    $sortby['title_desc'] = 'Reverse-Alphabetically';&#60;br /&#62;
    $sortby['price_desc'] = 'Price (highest to lowest)';&#60;br /&#62;
    $sortby['date_asc'] = 'Oldest to newest';&#60;br /&#62;
    $sortby['sku_asc'] = 'Sort by SKU';&#60;/p&#62;
&#60;p&#62;    return $sortby;&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;===============================================&#60;/p&#62;
&#60;p&#62;Before actually using the code, I would like to know:&#60;br /&#62;
- is my coding correct?&#60;br /&#62;
- how can I finally address/access the _sku?&#60;br /&#62;
In the single product page there is the field SKU - is it enough to use this or do I have to add a custom field?&#60;/p&#62;
&#60;p&#62;Thanks for your assistance.&#60;/p&#62;
&#60;p&#62;Best regards, Katharina
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
