-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot use orderby in shortcode, this plugin overrides it #17
Comments
hey @n9yty thanks for the report here! can you please let me know what version of the plugin you're using? Here's what I see using WooCommerce 3.4.5 + WooCommerce Extra Product Sorting Options 2.7.2:
I know you'd noted this code section in the forums, but if you'll look a bit further, you'll see that it also has a safety check for the shortcode arguments to respect them. On WooCommerce pages, we have to assume we'll be using the Could you please clarify what you're seeing here, or where you're using this shortcode so I can try to replicate this issue? thanks! |
Very strange indeed. We are current on plugins, WooCommerce Extra Product Sorting Options Version 2.7.2, WooCommerce Version 3.4.5 also. I just made a brand new prodcut, changing nothing in the default settings (although maybe that doesn't mean all our defaults are your defaults), and simply inserted this into the description: [products ids="32424, 33041, 35662, 2645, 4842, 7524" orderby="menu_order"] They are sorting alphabetically, not by menu_order. (using preview to view product, URL looks like: '/?post_type=product&p=1203845&preview=true') If I re-implement my patch, they sort by menu_order. (url looks the same '/?post_type=product&p=1203845&preview=true') So, nothing is being passed as a param in the URL. If I put that same shortcode in a Page, it works consistently, sorted by menu_order, regardless of whether my patch is in place or not, it only seems to be affected if it is on a product page. Let me know how I can help further debug this. |
I also tested various other sort parameters. For example, if I used 'popularity' as you did, limiting it to three, they did sort non-alphabetically. However, if I then put order="DESC" it did not change the sort order. I didn't try all possible options, but 'date', 'id', 'title' don't work, I don't think we have ratings so that doesn't work. NOthing seems to respect the 'order' ASC/DESC parameter. |
Sorry for the noise, but I just read more carefully what you wrote: "On WooCommerce pages, we have to assume we'll be using the $_GET value because these pages will output the sorting dropdown," Our use case is such that we have a WooCommerce product page using a product shortcode, it does not present a sorting drop-down, so $_GET is not present. The code, as I understand it, in that case just uses the default which is why I had to override it to look for a shortcode defined value. I'm not saying my patch is the right fix, but I guess you have not expected the use of a [products] shortcode to list other products with a custom sort order on a WooCommerce product page? I don't know what ou would do in the case of having a dropdown sort menu on a page that also specified a hard-coded sort option in the shortcode. I don't know fi that is a real-world scenario or not. |
@n9yty thanks for the clarification here! I've tested a product page as well, and unfortunately I'm still not able to replicate any of these issues. Here's my results (outputting product details for reference):
Could you please install the Transients Manager plugin and use it to delete all transients on your site, ensure all other plugins are deactivated except WooCommerce + Extra Product Sorting Options, then try again? Your site may be returning cached results for these shortcodes, which clearing transients should reveal. |
Hi Beka, thanks for digging into this, by the way. At this point, I don't know what to say, I cannot make it go away and you cannot duplciate it.... I installed Transients Manager and deleted all transients Problem persists, products still are sorting alphabetically instead of by menu_order with that shortcode. I deleted the Extra Sorting plugin and re-installed it, no change. Here is the settings column: If you have any thoughts on how I might help provide more debugging information, let me know. I will keep working on it. Also, if you can help me see the section where you are respecting the parameter, it might help me to debug it a bit more. I'll try below, but if I am missing something please let me know. As I see it, you are applying add_new_shop_ordering_args() to the filter woocommerce_get_catalog_ordering_args. This will filter any product request, as I understand it. In add_new_shop_ordering_args() it looks to see if $_GET['orderby'] is set. I believe this is where you are expecing it should be set for woocommerce product pages, shortcode or otherwise. In our case, looking at headers in the broswer debugger view, this is not set for the request. The only query string parameters are p, post_type, and preview {as I am looking at a preview of the product, it isn't published). But this is probably for the outer container product, not the shortcode. So inside add_new_shop_ordering_args() I inserted a debug statement at the top to capture a few things:
In the page output, I see this output twice, once after the page title and once after the product description header, right before the shortcode contents are displayed. DEBUG GET contents: Array ( [post_type] => product [p] => 1203845 [preview] => true ) If $_GET['orderby'] is not defined, the code after the test would apply the standard sorting. The next code section that specifically looks for the $sort_args['orderby'] does not apply here becuase is_woocommerce() is true as this is a product page. So it seems that in your case/testing, the $_GET['orderby'] is set when the shortcode fires, and for some reason it is NOT set here. The question is WHY is it different? Any thoughts on where to go from here? Small note, that if I change the URL to manually include an orderby parameter, the sort order works: https://testsite/store/test-sort-order/?orderby=menu_order And, maybe not helpful, but the filter "woocommerce_shortcode_products_query" passes these to me: $query_args: $atts: $loop_name: |
@bekarice Maybe you have given up on me since it seems something strange is going on. :) Is there any more I can do to help debug this? |
@n9yty nope, just been out of office for most of the past 2 weeks. :) the additional information here helped! I was able to replicate this after some settings adjustments. Could you apply this change and let me know if it resolves the issue for you? thanks! |
Thanks, @bekarice, that takes care of things here for us! And thanks for your awesome WooSesh presentation. |
excellent, we'll get this included in the next release then, thanks for hanging with me here @n9yty 😸 and glad to hear you were able to attend WooSesh! Brian and Patrick did a wonderful job, I appreciate you tuning in! 📺 🍻 |
addressed by #18 -- closing this, pending deploy thanks! |
Just to say thank you! The official Woo documentation references the incorrect code which results in shortcodes not working, your fix works perfectly, thank you for publishing on github! |
I posted here:
https://wordpress.org/support/topic/product-shortcode-in-product-not-respecting-orderby/
But basically, it seems as though this plugin, in the attempt to order everything by the chosen order, is also overriding shortcodes.
In particular we are trying to use the [products] shortcode with a custom orderby, and with this plugin active it is overriding it and instead forcing the default sort to be used regardless of what we specify in the shortcode.
I had suggested a change in that forum post, but I don't know if it would be the right way to handle it or have other side-effects in how the plugin is supposed to operate.
The text was updated successfully, but these errors were encountered: