Hello!
There are some built-in product types in WooCommerce: simple, variable, external. I'd like to create a vica-versa relationship with one product to another, based on product type. The simple products should be paper-based books, while the external products should be books sold digitally (ebook).
If I use this code, two META BOX apperas, and I can select the elements, but this is not OK, because I do not want to see tho boxes. When I set the 'reciprocal' setting to true, only one box appears, but the same on both product types. How can I solve it so that only the right one is displayed?
\MB_Relationships_API::register([
'id' => 'simple_product_to_external_product',
'reciprocal' => false,
'from' => [
'object_type' => 'post',
'post_type' => 'product',
'meta_box' => [
'title' => __('Paper based version', 'my-plugin-textdomain'),
'context' => 'normal',
'priority' => 'high'
],
'field' => [
'name' => __('Product', 'woocommerce'),
'placeholder' => __('Select a paper based version', 'my-plugin-textdomain'),
'query_args' => [
'tax_query' => [['taxonomy' => 'product_type', 'field' => 'slug', 'terms' => 'external']]
],
'max_clone' => 1,
'js_options' => [
'placeholder' => __('Select a product', 'my-plugin-textdomain')
]
]
],
'to' => [
'object_type' => 'post',
'post_type' => 'product',
'meta_box' => [
'title' => __('Digital (eBook) version', 'my-plugin-textdomain'),
'context' => 'normal',
'priority' => 'high'
],
'field' => [
'name' => __('Product', 'woocommerce'),
'placeholder' => __('Select a digital (eBook) version', 'my-plugin-textdomain'),
'query_args' => [
'tax_query' => [['taxonomy' => 'product_type', 'field' => 'slug', 'terms' => 'simple']]
],
'max_clone' => 1,
'js_options' => [
'placeholder' => __('Select a product', 'my-plugin-textdomain')
]
]
]
]);