What I would like to do is two fold
I would like to create a relationship between and order and another content type.
I would like to add custom fields to an order.
I can add custom fields to and order and it shows when editing the order. But when trying to make a relationship, order does not show up as one of the types
Why can I add fields but not relationships to an WooCommerce Order?
Thanks
Steve Ringwood
Hi there,
I guess it is because the Order post type is private and it can not be shown in the relationship GUI.
Let me ask or a second opinion and get back to you.
Hi there,
Ok, so the reason that you do not see the Order post type in the Relationship GUI is that the Woocommerce Order is private.
Please consider that it must be a good reason that Woocommerce made that post type private and not public.
It is possible to make the Woocommerce order public:
add_filter( 'register_post_type_args', 'customize_order_post_arg', 10, 2 );
function customize_order_post_arg( $args, $post_type ) {
// Let's make sure that we're customizing the post type we really need
if ( $post_type !== 'shop_order' ) {
return $args;
}
// make this order post type public
$args['public'] = true;
return $args;
}
Adding custom code in Toolset:
https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/
Or you can add the code to the functions.php of your theme.
If the Order gets public you can see the Order post type in the relationship GUI in Toolset.
Warning: By changing the Woocommerce Order post type from private to public you change the core of Woocommerce. That might have consequences as you manipulate the code that was intended to work the other way.
So please be warned that you might get unexpected behaviors that are not known or tested.
Thank you.
From my perspective, a relationship is just another field, since toolset allows me to add fields to an order, it seems logical I could add it to a relationship. In general this would seem safer than making shop order public
Hi there,
That is not the case. A relation is between two post types. It is not another field.
Woocommerce Order is a post type but it is private as I mentioned. That is why if you want to have it in the relationship GUI you will need to follow the steps above to make it public.
Thanks.
I realize it is not another field, but logically why do relationships care if the content is private or not?
Clearly fields do not and I see no logical reason relationships should. For the reasons you mentioned I would prefer to make an order public. I will simple need to code a custom approach.,
Hi there,
The difference is that a custom field in Toolset uses the native WordPress functionality as it has the same codebase and it uses the same functions.
The relationship is something different and Toolset has its own tables to handle and is not meant to be used for private posts.
The bottom line is this:
- Toolset can have a relationship if you do what I mentioned to make sure Order is public in Woocommerce.
- If you want to have private posts available in the relationship GUI you are welcome to ask about this as a feature request:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
Thanks.