How to Add a Surcharge Percentage to A...
Enhance your WooCommerce store with this code snippet to easily add a surcharge perce...

WPCodeBox
430
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;
}
}





