Support » Plugin: WooCommerce » Add a class to dashboard order row (if order has post meta)
Add a class to dashboard order row (if order has post meta)
-
Firstly, I appreciate that this is custom coding and not core code – I am posting this as I’d like to know the answer but it may not be possible and therefore could require an amend of the core code. I was going to put this on Stack Exchange but they deem WooCommerce as off topic and point you to this forum.
I simply want to add a CSS class to any order row in the dashboard orders page where the order has a specific post meta attached.
I can do this by adding a custom column and then doing some jQuery to read that column and add that class but it seems a really hacky solution, I don’t really need the column and I would have to wait for all those elements to load before applying the class.
I can’t find anyway to do this using the hooks/filters available.
Can anyone help?
-
This topic was modified 2 years, 9 months ago by
steveo2000.
-
This topic was modified 2 years, 9 months ago by
-
Hi there,
The easiest would be to override the orders template used by WooCommerce for the My Account page. There’s a guide on how to do that available at https://docs.woocommerce.com/document/template-structure/
The exact template that you’d need to override can be found here: https://github.com/woocommerce/woocommerce/blob/master/templates/myaccount/my-orders.php
In addition, Iām going to leave it open for a bit to see if anyone is able to chime in to help you out.
I can also recommend the following places for more development-oriented questions:
* WooCommerce Slack Community: https://woocommerce.com/community-slack/
* Advanced WooCommerce group on Facebook: https://www.facebook.com/groups/advanced.woocommerce/Sorry – I am not talking about the frontend, this is on the dashboard orders list.
-
This reply was modified 2 years, 9 months ago by
steveo2000.
Ah, thanks for elaborating a bit more. The admin side of things fall a but outside of my expertise. Let’s keep the thread open somewhat to see if anyone else from the community has any ideas š
@steveo2000 I think your best bet is going to be the
get_post_class
function called here:
https://github.com/WordPress/WordPress/blob/4.9.6/wp-admin/includes/class-wp-posts-list-table.php#L1194This function’s output is filterable here:
https://github.com/WordPress/WordPress/blob/4.9.6/wp-includes/post-template.php#L543The drawback here is that if you add a filter, it will be called upon for every page view, so you would need to do some checks to just
return
if the proper orders page in the admin isn’t matched.Hope that helps. Going to set this as resolved for now, as it’s out of scope for WooCommerce. You might be able to get some Stack Exchange help if you post that you just want to do this for posts, or custom posts rather than “WooCommerce Orders” since they are just custom posts types any way š
Thank you for your help – yes this works for me!
-
This reply was modified 2 years, 9 months ago by
- The topic ‘Add a class to dashboard order row (if order has post meta)’ is closed to new replies.