How to Automatically Update WooCommerc...
This WooCommerce code snippet automatically updates cart quantities, eliminating the ...

WPCodeBox
804
Empower site administrators to automatically check “Virtual” and “Downloadable” product options in WooCommerce based on user roles, streamlining product setup.
add_filter( 'product_type_options', 'autocheck_virtual_downloadable');
function autocheck_virtual_downloadable( $args ){
//Set Your targeted user role(s) here
$targeted_user_roles = array( 'administrator', 'vendor' );
// Get the current user object
$user = wp_get_current_user();
// Get the roles of current user
$user_roles = $user->roles;
if ( array_intersect( $targeted_user_roles, $user_roles ) ){
// Auto-Check Virtual and Downloadable Checkboxes
$args['virtual'] ['default'] = "yes";
$args['downloadable']['default'] = "yes";
return $args;
}
}





