I want to have Variable Products that grant access to a specific file no matter the Variation. I tried simply enabling the downloadable button for variable products and overriding is_downloadable however while the data in the REST API is like I want it, in the product editor downloadable is unchecked and Downloadable files is hidden until it is checked again.
My simple plugin currently looks like this
function enable_downloadable($product_type_options)
{
$product_type_options['downloadable']['wrapper_class'] = 'show_if_simple show_if_variable';
$product_type_options['downloadable']['default'] = 'yes';
$product_type_options['virtual']['wrapper_class'] = 'show_if_simple show_if_variable';
$product_type_options['virtual']['default'] = 'yes';
return $product_type_options;
}
add_filter( 'product_type_options', 'enable_downloadable' );
function is_downloadable($downloadable, $product)
{
return 'yes';
}
add_filter('woocommerce_is_downloadable', 'is_downloadable', 10, 2);
function is_virtual($virtual, $product)
{
return 'yes';
}
add_filter('woocommerce_is_virtual', 'is_virtual', 10, 2);
function save_metadata($post_id)
{
update_post_meta( $post_id, '_downloadable', 'yes' );
update_post_meta( $post_id, '_virtual', 'yes' );
}
add_action( 'woocommerce_process_product_meta_variable', 'save_metadata');
add_action( 'woocommerce_process_product_meta_simple', 'save_metadata');
Any simple way to achieve this?