Tagged: add, remove, sort by, sorting, woocommerce
-
AuthorPosts
-
April 1, 2015 at 5:37 pm #422047
Hi!
I’m wondering if this is something you can help with, I’ve been looking for a solution while thinking this is a woocommerce problem, but then I read that maybe the theme one uses could get in the way, so if that’s the case, could you assist me please?
I wan’t to delete some sorting options from my Shop, as well as to add others. I found 2 plugins for this:
– WooCommerce Extra Product Sorting Options: adds options.
– WooCommerce Remove Product Sorting: removes default options.I installed them, activated them and they work, they show me the options to delete and add sorting: . The problem is that even though I saved the settings and that everything seems to be ok, the “Sort by” dropdown in the Shop remains the same: . I also tried with other plugins and some PHP solutions I found online but the “Sort by” dropdown never changes, that’s why I’m inclined to believe that maybe it has to do with your theme and there’s something from your side I need to adjust to make this work.
Thanks for your help!
- This topic was modified 9 years, 7 months ago by therqworld.
April 2, 2015 at 2:36 am #422244UPDATE:
I also contacted the plugin author about it, she said:
“Hey! looks like your theme has probably overridden the sorting dropdown — could you please try it out in a default theme, i.e. TwentyTwelve, and let me know if this persists? Thanks!”
I did so and she was right, her plugin works in other themes, so it’s something your theme is overwriting, could you tell me how to avoid that?
Thanks!
- This reply was modified 9 years, 7 months ago by therqworld.
April 2, 2015 at 10:27 am #422377Hey!
Thank you for coming back.
I checked the code and this dropdown is hardcoded in our theme. You find it in enfold\config-woocommerce\config.php line 1128ff.
Out of the box there is currently no possibility for a 3-rd party plugin to hook into it and change it.
I will forward this to Kriesi, if he wants to implement a solution for it.
Cheers!
GünterApril 2, 2015 at 4:05 pm #422551Thanks for the reply Günter!
I think a lot of users would appreciate a solution for this, so I hope your team decides to implement it soon. In the meantime, I must say I don’t know much about PHP, I tried making the line 1128 a comment and uploaded the file but there were no changes, I also tried it from line 1126 to 1130 (made the whole function a comment) and then the entire function (from line 1081 to line 1157) but there were no changes on my site.
Could I get further assistance as to what to delete/change to remove this default dropdown?
Thanks again!
April 2, 2015 at 5:47 pm #422649Hey!
To complete remove the dropdown lists:
Line 1091:
add_action( 'woocommerce_before_shop_loop', 'avia_woocommerce_frontend_search_params', 20);
replace with:
// add_action( 'woocommerce_before_shop_loop', 'avia_woocommerce_frontend_search_params', 20);
At a quick glance I did not find a WC hook to add the select boxes. But maybe the plugin author can help you with a hook to display his selectboxes. Add his hook instead of ours.
If you have troubles with that, post us the hook and we will try to help you.
Cheers!
GünterApril 2, 2015 at 6:15 pm #422673Hi Günter! Thanks for the quick reply :)
Your latest reply made me realize I was going through the config.php file of version 3.0.2 instead of 3.1.3, so that’s why I wasn’t seeing what you wanted me to see in line 1128 and got confused. Sorry about that… in the 3.1.3 version line 1128 has html, that I get! LOL
Now that I’m working on the latest version I was able to remove the sorting options I didn’t want, thanks! – but now I wonder: could I add a new sorting option to this code? I would like to also sort by an attribute (like “Size” for example), is this something you could assist me with as well?
Thanks again and sorry for the confusion on file versions.
Cheers!
- This reply was modified 9 years, 7 months ago by therqworld.
April 4, 2015 at 4:53 am #423346Hey!
You can use the default Woocommerce Layered Nav widget if you want to sort products by attribute.
Regards,
IsmaelApril 5, 2015 at 3:57 am #423557Thanks Ismael!
A new question now: is there a way to make the Default sorting to be the ‘date’ instead of the products names?
Thanks!
April 6, 2015 at 9:45 pm #424270Hi!
Please add following code to Functions.php file in Appearance > Editor
add_filter('woocommerce_default_catalog_orderby', 'change_woocommerce_default_sorting'); function change_woocommerce_default_sorting() { return 'date'; }
Regards,
YigitApril 6, 2015 at 10:20 pm #424284Thanks so much Yigit!
Only one thing missing: I want to also change the name, I want to order by date (which your code does perfectly) but I don’t want it to say “Date”, I want it to say “Default”.
I actually already accomplished this by changing the value in the config.php file (enfold\config-woocommerce\config.php – I changed “Date” to “Default” in line 1102) but if you have a code that I can add to functions.php instead I would really appreciate it, as I’m guessing my work will be overwritten with the next update of the theme.
Thanks for all your help! your team and theme rock!
April 6, 2015 at 11:01 pm #424307Hey!
Can you please post a screenshot and show the changes you would like to make? Not sure if i understood you clearly :)
Best regards,
YigitApril 6, 2015 at 11:43 pm #424347Sure Yigit! Let me see if I can express myself better, here’s the thing:
1. Your code did 1 of 2 things I wanted: it made “Date” the default sorting. Now when I go to products, they’re sorted by Date automatically, so cool! that’s done :)
2. The 2nd thing I want, is that instead of saying “Date”, the user views “Default Order”, and I achieved this by changing line 1102 (see screenshot below), instead of “Date”, I put “Default Order” (I placed a red dot next to the change for you)
The other dots in this image, just to give you a full scope:
– line 1099, yellow dot: I changed the original “Default Order” title to avoid confusions, I added “Hidden”. This is really just for my benefit, because it doesn’t affect what the users will see.
– lines 1132, 1134, 1136: made these lines into comments to hide these sorting options (so my change in line 1099 it’s not visible to users anyway, like I said, that one it’s just for my benefit)3. What do I want? To achieve what I did in line 1102 with a function that I can add to functions.php.
4. What would I also like, if possible: to also achieve what I did in lines 1132, 1134 and 1132 with a function that I can add to functions.php.
Basically my goal is to have these changes on my child theme instead of the parent theme because I know that with every update I’ll have to redo this. However, if this beyond the scope of your support I understand, and luckily, I already have a solution, it’s just not as elegant as it would be if it were in functions.php.
Hope it’s clear now, if not let me know :)
Thanks a lot!
April 8, 2015 at 3:48 am #425053Hi!
You can copy the whole function inside the functions.php file and it will override the default code:
add_action( 'woocommerce_before_shop_loop', 'avia_woocommerce_frontend_search_params', 20); function avia_woocommerce_frontend_search_params() { global $avia_config; if(!empty($avia_config['woocommerce']['disable_sorting_options'])) return false; $product_order['default'] = __("Default Order",'avia_framework'); $product_order['title'] = __("Name",'avia_framework'); $product_order['price'] = __("Price",'avia_framework'); $product_order['date'] = __("Date",'avia_framework'); $product_order['popularity'] = __("Popularity",'avia_framework'); $product_sort['asc'] = __("Click to order products ascending", 'avia_framework'); $product_sort['desc'] = __("Click to order products descending", 'avia_framework'); $per_page_string = __("Products per page",'avia_framework'); $per_page = get_option('avia_woocommerce_product_count'); if(!$per_page) $per_page = get_option('posts_per_page'); if(!empty($avia_config['woocommerce']['default_posts_per_page'])) $per_page = $avia_config['woocommerce']['default_posts_per_page']; parse_str($_SERVER['QUERY_STRING'], $params); $po_key = !empty($avia_config['woocommerce']['product_order']) ? $avia_config['woocommerce']['product_order'] : 'default'; $ps_key = !empty($avia_config['woocommerce']['product_sort']) ? $avia_config['woocommerce']['product_sort'] : 'asc'; $pc_key = !empty($avia_config['woocommerce']['product_count']) ? $avia_config['woocommerce']['product_count'] : $per_page; $ps_key = strtolower($ps_key); $nofollow = 'rel="nofollow"'; //generate markup $output = ""; $output .= "<div class='product-sorting'>"; $output .= " <ul class='sort-param sort-param-order'>"; $output .= " <li><span class='currently-selected'>".__("Sort by",'avia_framework')." <strong>".$product_order[$po_key]."</strong></span>"; $output .= " <ul>"; $output .= " <li".avia_woo_active_class($po_key, 'default')."><a href='".avia_woo_build_query_string($params, 'product_order', 'default')."' {$nofollow}> <span class='avia-bullet'></span>".$product_order['default']."</a></li>"; $output .= " <li".avia_woo_active_class($po_key, 'title')."><a href='".avia_woo_build_query_string($params, 'product_order', 'title')."' {$nofollow}> <span class='avia-bullet'></span>".$product_order['title']."</a></li>"; $output .= " <li".avia_woo_active_class($po_key, 'price')."><a href='".avia_woo_build_query_string($params, 'product_order', 'price')."' {$nofollow}> <span class='avia-bullet'></span>".$product_order['price']."</a></li>"; $output .= " <li".avia_woo_active_class($po_key, 'date')."><a href='".avia_woo_build_query_string($params, 'product_order', 'date')."' {$nofollow}> <span class='avia-bullet'></span>".$product_order['date']."</a></li>"; $output .= " <li".avia_woo_active_class($po_key, 'popularity')."><a href='".avia_woo_build_query_string($params, 'product_order', 'popularity')."' {$nofollow}> <span class='avia-bullet'></span>".$product_order['popularity']."</a></li>"; $output .= " </ul>"; $output .= " </li>"; $output .= " </ul>"; $output .= " <ul class='sort-param sort-param-sort'>"; $output .= " <li>"; if($ps_key == 'desc') $output .= " <a title='".$product_sort['asc']."' class='sort-param-asc' href='".avia_woo_build_query_string($params, 'product_sort', 'asc')."' {$nofollow}>".$product_sort['desc']."</a>"; if($ps_key == 'asc') $output .= " <a title='".$product_sort['desc']."' class='sort-param-desc' href='".avia_woo_build_query_string($params, 'product_sort', 'desc')."' {$nofollow}>".$product_sort['asc']."</a>"; $output .= " </li>"; $output .= " </ul>"; $output .= " <ul class='sort-param sort-param-count'>"; $output .= " <li><span class='currently-selected'>".__("Display",'avia_framework')." <strong>".$pc_key." ".$per_page_string."</strong></span>"; $output .= " <ul>"; $output .= " <li".avia_woo_active_class($pc_key, $per_page)."> <a href='".avia_woo_build_query_string($params, 'product_count', $per_page)."' {$nofollow}> <span class='avia-bullet'></span>".$per_page." ".$per_page_string."</a></li>"; $output .= " <li".avia_woo_active_class($pc_key, $per_page*2)."><a href='".avia_woo_build_query_string($params, 'product_count', $per_page * 2)."' {$nofollow}> <span class='avia-bullet'></span>".($per_page * 2)." ".$per_page_string."</a></li>"; $output .= " <li".avia_woo_active_class($pc_key, $per_page*3)."><a href='".avia_woo_build_query_string($params, 'product_count', $per_page * 3)."' {$nofollow}> <span class='avia-bullet'></span>".($per_page * 3)." ".$per_page_string."</a></li>"; $output .= " </ul>"; $output .= " </li>"; $output .= " </ul>"; $output .= "</div>"; echo $output; }
Cheers!
IsmaelApril 10, 2015 at 1:33 am #426267Hi Ismael,
Thank you so much for the tip! Worked perfectly!
Cheers!
- This reply was modified 9 years, 7 months ago by therqworld.
-
AuthorPosts
- The topic ‘WooCommerce "Sort by" dropdown’ is closed to new replies.