Home › Toolset Professional Support › [Resolved] Hide Fields Table (Post Relationships) on WooCommerce products
Problem:
How to set the option "Do not show management options for this post type" for WooCommerce Products to hide the post relationships metabox.
Solution:
The option is not available because the Products post type is not managed by Types. You can add a code snippet to your functions.php file to hide the post relationships metabox like so:
function hide_product_post_relationships($hidden, $screen) { if (is_admin()) { global $post; if ('product' === $post - > post_type) { $hidden[] = 'wpcf-post-relationship'; return $hidden; } } } add_filter('hidden_meta_boxes', 'hide_product_post_relationships', 10, 2);
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+01:00)
Tagged: Setting up post relationship
Related documentation:
This topic contains 9 replies, has 2 voices.
Last updated by Jakob 7 years, 10 months ago.
Assisted by: Nigel.
How can I do this on WooCommerce products, which I can't access in Toolsets post type listing?:
"This is done in Types > Post Types > your_parent_post_type > Edit > Post relationship > the_child_post > Select Fields There you will choose the option "Do not show management options for this post type""
https://toolset.com/forums/topic/hiding-children-when-editing-parent/
Is there a way to do it in code?
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+01:00)
Sorry Jakob,
I'm not sure which table you are trying to hide, could you show me a screenshot of the relevant part of the page and then I'll help you with a solution.
Thanks
Here you go.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+01:00)
Can I check what your post relationships are?
The WooCommerce 'Product' custom post type isn't managed by Types, but I'm guessing that you have created another post type in Types where you have specified a relationship to Products.
In the attached screenshot you should be able to make out behind the modal that I have indicated that Products will be child posts of my custom post type. Alongside the checkbox for Product appears a link "Select fields" which opens the modal you can see when clicked, whereby you can choose the option "Do not show management options for this post type".
The Select fields link won't work until you have first saved the post type after selecting the Product checkbox.
Is that what you were looking for?
I'm looking for that possibility on Product which is one of three parents to a child post type called Course Date.
Can I do the same thing programmatically?
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+01:00)
When your product is a parent rather than a child the GUI doesn't have the option you require because the product custom post type is not managed by Types.
This might be a blunt instrument because it will disable the product relationship view on all screens but you could refine it if needed. You need to add the Post Relationship meta box to the list of hidden metaboxes by adding the following to your functions.php file for your theme:
/** * Custom code to change hidden meta boxes * */ function hide_post_relationships( $hidden, $screen ) { $hidden[] = 'wpcf-post-relationship'; return $hidden; } add_filter( 'hidden_meta_boxes', 'hide_post_relationships', 10, 2 );
I think that code example is exactly the pointer I needed.
I will get back here later with my final solution.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+01:00)
Hi Jakob
Let me know how you get on so I know if I can close the ticket, thanks.
I ended up doing this:
function product_hide_coursedate_relationship( $hidden, $screen ) { if ( is_admin() ) { global $post; if ( 'product' === $post->post_type ) { $hidden[] = 'wpcf-post-relationship'; return $hidden; } } } add_filter( 'hidden_meta_boxes', 'product_hide_coursedate_relationship', 10, 2 );
Thanks for the help.
I have a correction to the solution in the previous post. That code worked with regard to removing the post relation box on products, but it also introduced a bug: The settings for Screen Options (the button in the upper right corner on post type edit screens) were not respected.
I am now using this code instead:
function product_hide_coursedate_relationship() { remove_meta_box( 'wpcf-post-relationship', 'product', 'normal' ); } add_action( 'add_meta_boxes', 'product_hide_coursedate_relationship', 10, 2 );
I found it here:
hidden link
So this was just an update. The issue is now even more resolved.